Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force a full screen Activity to remeasure/redraw on resume?

Tags:

java

android

Edited to add more details: (originally asked nearly two months ago...still haven't found a solution)

I have an activity with a somewhat complicated view. Not complicated in a technical sense...there's just a lot going on. All activities in this particular app are set to FullScreen NoTitleBar, and they're all set to Landscape orientation. I noticed early on in development when the app is hidden and then resumes, there was an infrequent tendency for the layout to slide down vertically as if to make room for the titlebar and statusbar.

Later on in development, the app now calls out to various external intents. I notice now that there is more of a tendency to make this same shift when resuming from an externally handled fired intent (such as creating a "chooser" intent or picking an image). I am able to reproduce it inconsistently using the exact same steps...sometimes it happens sometimes it doesn't. It seems as if there's a race condition in between various phases of measuring and laying out. I assume that one of these steps that the system is doing for me is checking for fullscreen and notitlebar, and making the necessary shift. This is probably happening late in some cases.

I put a bunch of logging, and calls to invalidate(), requestLayout(), etc trying to maybe catch the race condition, but the problem seems external to my layouts. The top() and bottom() values of my root layout are always 0 and the height of my screen, respectively, even when I'm logging this while the issue is occurring.

Is there some other method of the Window, WindowManager or any other system view-related object that I can force a full remeasure, redraw, re-check for current theme/style flags?

like image 532
Rich Avatar asked Dec 01 '10 20:12

Rich


2 Answers

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.

like image 192
r-hold Avatar answered Oct 02 '22 12:10

r-hold


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.
     */
}
like image 22
Paweł Prażak Avatar answered Oct 02 '22 14:10

Paweł Prażak