Separate admob banner ads across all activities

I tried to find an answer to this problem, couldn't find an exact answer.

I have 5-6 operations including the splash screen at the beginning. Apart from splash in other views, I want to display a banner ad at the bottom of the screen. during the transition from one activity to another, I want to keep the same ad banner without refreshing. This means that a portion of the banner always stays (but is updated with new banners) in the view while the actions and layout change.

What's the best way to do this?

Some people say this is impossible. Show permanent admob banner ad in all activities

+3


source to share


2 answers


Instead of actions, use different fragments in the main activity and place a banner at the bottom of the main activity so that fragments are called instead of activities and your banner is the same. Customize your action layout to different fragments.



Follow this link: Android Snippets

+2


source


Let me help you dear. I achieved this in the following way and is very simple to do.

First of all, use the same banner ad layout code in every action you take.

Now do one thing. Declare a variable like this below your entire activity class name.

    private AdView mAdView;

      

After that, use this piece of code inside your onCreate () function for each activity.

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

      



After that, your ad will be present / displayed in every action.

You can use my xml folding banner:

    <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_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="PASTE YOUR AD UNIT ID HERE">
</com.google.android.gms.ads.AdView>

      

Don't forget to add this below the xmlns inside your xml layout. Place this below a line of code similar to it.

              xmlns:ads="http://schemas.android.com/apk/res-auto" 

      

Also use your ad unit ID where I mentioned to use it.

0


source







All Articles