Edited to add more details: (originally asked nearly two months ago...still haven\'t found a solution)
I have an activity with a somewhat complicate
I have found a Solution to this:
@Override
protected void onResume() {
Log.e("", "onResume");
super.onResume();
//this is a simple Splash with "Game paused" Text inside! in my main.xml
final LinearLayout gamePause_text = (LinearLayout) findViewById(R.id.gamePause_text);
OnGlobalLayoutListener asdf = new OnGlobalLayoutListener(){
public void onGlobalLayout() {
Log.e("", "onGlobalLayout");
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
gameSurface.onResume(); //OpenGL Surface onResume();
gamePause_text.getViewTreeObserver().removeGlobalOnLayoutListener(this);
};
gamePause_text.getViewTreeObserver().addOnGlobalLayoutListener(asdf);
}
i had exactly the same problem and also tried several aproches (as the ones mentioned above). None of them worked. However i found the following workaround:
protected void onResume() {
super.onResume();
handler.postDelayed(new Runnable() {
public void run() {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}, 1000);
}
the view will do a short flicker in this procedure, but at least it doensn't stay croped. A clean solution still needs to be found. However this supports your thesis that there is some kind of timing or race problem.
Have you set FullScreen NoTitleBar in your manifest or in code? If you use code, it may be that it is getting rendered before your code kicks in?
<application android:label="@string/app_name" android:icon="@drawable/icon" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
I understand that you can set themes on individual activities in an application. Do you? and do they conflict with your application settings?
In my case this behavior was triggered by resume from lock screen. No idea why but after adding empty overloaded function it was fixed (but I tested it only on my HTC Wilfire). It may be a different bug thou.
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
/* Workaround a probable Android bug with fullscreen activities:
* on resume status bar hides and black margin stays,
* reproducible half of the time when coming back from lock screen
* (tested on HTC Wildfire)
* No idea why but this empty overload method fixed it.
*/
}
I Fixed it by setting the theme for application rather than for individual activities.
<application
android:icon="@drawable/icon"
android:installLocation="auto"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
This worked for me. This problem occurs if the next Activity we launch isnt a Full screen Activity and current Activity is a Full screen Activity.
Have you tried this in onResume()?
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN );