Layout cannot be removed - android

I am trying to remove the layout when the apps starts.
I removed "setContentView" from the MainActivity.java file but still the layout is showing when the activty starts..
How can I remove the layout??
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setVisible(false);
}
}

try adding this to your manifest, inside activity android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"

Related

Disable fullscreen mode after setting FLAG_LAYOUT_IN_SCREEN in Android

I have to inherit a custom main activity class which is a 3rd party lib and I cannot make any change to the class. This class adds FLAG_LAYOUT_IN_SCREEN to the window and it causes the app to be on full screen. However, I wanna prevent this behavior. So, the question is how can I clear/disable the full screen mode and can display navigation bar/status bar?
Here is the custom main activity class
public class CustomActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
setContentView(new FrameLayout(this));
// rest...
}
}
Here is my activity class:
public class MyActivity extends CustomActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// tried these attempts below, but none of them prevented
// the fullscreen mode which hides navigation bar and status bar.
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
}
Note: You can also test it on a sample app easily. You would notice once you add the FLAG_LAYOUT_IN_SCREEN, full-screen mode remains for different attempts as well.
public class MainActivity extends Activity {
private FrameLayout mainLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().addFlags(FLAG_LAYOUT_IN_SCREEN);
setContentView(new FrameLayout(this));
this.getWindow().clearFlags(FLAG_LAYOUT_IN_SCREEN);
this.getWindow().addFlags(FLAG_KEEP_SCREEN_ON);
}
Please apply the following to the app to not be as full screen (showing status bar)
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

How to prevent the Screentshot in the entire android app without repeating the same code

Hi everyone i want to block the Screenshot in my app. I got the first problem solve from here.
But now the thing is I have more than 10 activity and 10 + fragment.
Is there any way to do this just by writing in the one class and giving it reference to the entire app.
Just like we make one Application class and in the AndroidMainfest.xml give that application class refrence.
You can implement a BaseActivity, and make all your activities extend this BaseActivity. In onCreate() of this activity set the flag. You need to ensure all your activities call super.onCreate() as follows:
BaseActivity.java
public abstract class BaseActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//set your flag here
...
}
}
Activity1.java
public class Activity1 extends BaseActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
}
}

Butterknife not detecting the source of event

I have just started working with Butterknife library and written the following code:
class myActivity extends AppCompatActivity
{
#BindView(R.id.button) Button app1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
public void selectApp(View b)
{
Button clicked=(Button)b;
if(clicked==app1)
Toast.makeText(this,"First App clicked",Toast.LENGTH_LONG).show();
}
}
here selectApp is attached through onClick in the xml view file.
But the problem is clicked==app1 is returning false even when pressing app1. The method is being called but the if condition is coming false.
Can anybody clarify.
Thanks
I think this would work:
if(clicked.getId()==R.id.button)
Also, you can use View b and not parse into a button:
if(b.getId()==R.id.button)
¿Is this your actual code? seems to lack an annotation on the method.

Android app without a layout

I'm a totally noob on Android, is there a way to execute an app without a layout? The process would be like: Click app icon -> run some code (Without prompting any window) -> display toast.
The trick is to open a transparent activity, show the toast and finish the activity, which makes it look like only the toast is displayed because the activity which opened was transparent.
To do this you can do.
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toast.makeText(this, messageToBeDisplayed, Toast.LENGTH_SHORT).show();
// finish the activity as soon as it opened.
this.finish();
}
}
Also you need to give a transparent theme to your activity by specifying it in AndroidManifest.xml, For which you can use NoDisplayeTheme provided by Android like this.
<activity android:name="TransparentActivity"
android:theme="#android:style/Theme.NoDisplay">
</activity>
Yes you can by adding:
android:theme="#android:style/Theme.NoDisplay"
in your activity in Android manifest.
Check this answer for more details.
Use this:
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toast.makeText(this, "", Toast.LENGTH_SHORT).show();
this.finish();
}
}
and in manifest file add: android:theme="#android:style/Theme.NoDisplay"

Android: Changing Inclination of phone returns me to the main.xml view

I've been developing an Android App and I have encountered a small problem when putting my phone horizontally.
At the moment I have two views: The main one (main.xml) and a login view (login.xml). When I turn my phone while being in the login.xml view, it returns me to the main.xml view. The same thing happens if the phone is in horizontal position + login.xml and I turn it again (goes back to main.xml).
It sees that the "OnCreate" is executed each time, here is the code for the app:
public class AppActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageButton bout= null;
bout = (ImageButton)findViewById(R.id.imageButton1);
bout.setOnClickListener(boutlisten);
}
private OnClickListener boutlisten = new OnClickListener(){
public void onClick(View v) {
setContentView(R.layout.login);
}
};
}
Thanks in advance!
Create new Activity which have setContentView(R.layout.login); and start Activity.
Like,
public class LoginActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
}
}
See here
Addendum: This is the code to launch the activity declared above. One should also declare the activity in the manifest file
private OnClickListener boutlisten = new OnClickListener(){
public void onClick(View v) {
Intent myIntent = new Intent(v.getContext(), LoginActivity.class);
startActivity(myIntent);
}
};
Also, as u must already be aware of..don't forget to declare the new activity in your AndroidManifest.xml
<activity android:name=".LoginActivity" />
Alternatively, you may also force your activity to run just vertically. Just add this to your Main activity tag in AndroidManifest.xml
<activity android:screenOrientation="portrait" ...../>

Categories

Resources