4

I'm experiencing very nasty bug trying to implement Admob in my application. I thought the problem is in my code, but after some investigation I found it present also in Android-Banner-Essentials example (available for download here). I wonder if anyone ever met this problem or maybe knows how to deal with it.

Basically, when application has both status and title bar disabled, it should use full screen. Banner Essentials example displays nothing but Admob banner on the very top of area available. I downloaded the example, changed only two things:

  • added my publisher ID to compile properly and receive any ads ;)
  • added one param to activity's manifest to disable title and status bar: android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

Compiled binary, no matter what device is it launched on (tried Nexus One, G1, Desire, different Android versions), is affected with the same issue:

  • When ad banner is displayed press Home,
  • Once taken back to home screen press and hold Home to see recently launched apps,
  • Select back Banner Essentials app.

My tests reveal that with 50% reproduction chance Admob banner doesn't go back to its position -the very top of the screen. To show better what I mean I prepared three screenshots:

http://img841.imageshack.us/g/correctz.png/

Important notices:

  • When app is resumed normally, banner is displayed just below status bar, and slides up until is aligned to the top screen border,
  • when error appears the banner doesn't move at all,
  • I couldn't reproduce the issue with any other interrupt (pressing Back, Power Button),
  • I think it may be somehow connected to gaining/losing focus (see screenshots).

My app is bit more complex than Banner Essentials so I started with searching the issue in my code, with no luck, thus tried to simplify the situation as much as possible and here are the results.

Does anyone know what may be causing the problem? Maybe some additional flags or properties have to be set to handle this behaviour?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
groob
  • 41
  • 3
  • Hi! Did you managed to solve the problem, or at least found the cause of it? (I've just bounced into it...) – vmatyi Sep 19 '11 at 10:15

2 Answers2

4

This one is referenced as an Android bug. There is no solution, just a workaround. You have to re-set Window Fullscreen about 1 second after onResume (to wait till the status bar finishes its fancy sliding out animation...), which will cause it to re/calculate the whole layout, "solving" the problem (with a quick jump to the correct positiin).

public void onResume()
{

  ...

    handler.postDelayed(new Runnable() {
        public void run() {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                             WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
    }, 1500); 

  ...

}

It's not good. But it's still the best available. More info here.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
vmatyi
  • 1,273
  • 10
  • 21
0

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.
     */
}
Paweł Prażak
  • 3,091
  • 1
  • 27
  • 42