Search code examples
androidadmobleadbolt

Admob pushes all content down (including window)!


I belive I have the most unique and weirdest problem of all.

So to keep it simple I have made the most simple layout in the world:

 <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
android:background="#4d9345"
        android:layout_height="match_parent" >


        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignParentTop="true"
            ads:adSize="BANNER"
            ads:adUnitId="@string/admob">
        </com.google.android.gms.ads.AdView>

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:text="Button" />

    </RelativeLayout>

And then the code:

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);



    setContentView(R.layout.myact);


    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest.Builder adRequest = new AdRequest.Builder();
   AdRequest req = adRequest.build();
    mAdView.loadAd(req);

}

SCENARIO 1:

If I launch this activity when pressing a button that starts this activity, it's all okay. The activity shows as expected (pic below):

enter image description here

SCENARIO 2:

If this activity is started from SCREEN OFF Broadcast receiver, it messes up the layout as soon the ad is loaded. All content including window is pushed down. (pic below):

enter image description here

You can see that even its parent (Relative Layout) was pushed down (as you can see above the ad is black gap).

SCENARIO 3:

If I make some changes to the XML layout code ana give admob view margin top:

android:layout_marginTop="25dp"

The result is that the content is not pushed down:

enter image description here

Things to note:

  1. This activity is launched under some circumstances but only when screen is turned off.

  2. If I don't use requestWindowFeature(Window.FEATURE_NO_TITLE); in my code, it works with no problem, but using this feature is cruical.

To make this problem even more strange: 3. It does this only on Samsung Galaxy S3 mini. It worked on HTC One, HTC Wildfire and some others without a problem. (But maybe there are devices that does exactly ike on galaxy s3 mini). 4. I've experienced this behaviour only on Admob and Leadbolt ads. Using Amazon, Mmedia, or even my own ads (pulled from my server), it worked with no problem..

Even tho I don't expect because It's the weirdest problem, I would really appriciate some help..

Thank you in advance.


Solution

  • It is probably a problem of hiding or showing the action bar properly and has to do something with the window flags.

    Check out at this old post, and try the solutions. It might work. Android - status bar prevents full screen