When my application is destroyed
and then resumed, a black bar appears where the soft navigation buttons would otherwise be. My application is meant to be fullscreen with no navigation buttons, so this bar blocks some of my content from view. I have only been able to reproduce this on Lollipop (not KitKat) and only when my application goes through destruction (not just a stop and start).
Is there something I'm missing or not setting correctly for Lollipop? I have debugged and verified that my calls to set flags are being made in both onCreate
and onWindowFocusChanged
whenever my activity is created, whether after destruction or a completely new instance.
If I leave and return to the activity or rotate the screen, the bar disappears and I see everything as usual.
Update - It makes no difference whether or not I also apply FLAG_FULLSCREEN
or FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
. Also, the buttons beneath the black bar can be clicked, at which point the black bar disappears before the next activity is loaded.
A screenshot where I highlight the black bar and show what I should see underneath it:
Here are the flags I set for fullscreen on my onCreate()
method.
mDecorView = getWindow().getDecorView();
// call before setContentView to avoid system bars briefly showing
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
System.out.println("checking os version");
if (currentapiVersion >= Build.VERSION_CODES.KITKAT) {
System.out.println("KitKat or newer");
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
);
} else{
System.out.println("Older than KitKat");
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
Here is where I do the same to ensure fullscreen onWindowFocusChanged()
@SuppressLint("NewApi")
@Override
public void onWindowFocusChanged(boolean hasFocus){
super.onWindowFocusChanged(hasFocus);
if(hasFocus){
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= Build.VERSION_CODES.KITKAT) {
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
);
} else{
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
}