Reputation: 1291
I tried to find answer to this problem, couldn't find a precise answer.
I have 5 to 6 activities including a splash screen at the start. Apart from the splash in other views I want to show a banner ad at the bottom of the screen. during the transition from one activity to another I want to retain the same banner with the ad without refreshing. That means the banner part stays always (but will refresh with new banners) in the view, while activities and there layout change.
What is the best way to implement this?
Some say impossible. Show a constant admob ad banner in all the activities
Upvotes: 4
Views: 3657
Reputation: 1
let me help you dear. I achieved it as follows and its very simple to do.
First of all use the same banner ad xml layout code in your each and every activity..
Now Do one thing Declare a variable as follows just below your all activity class name.
private AdView mAdView;
After this use this code snippet inside your onCreate() function of every activity.
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.build();
mAdView.loadAd(adRequest);
Thereafter your same banner ad will be present/shown in every activity.
You can Use My xml ad banner layout :
<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>
Dont forget to add this below xmlns inside your activity xml layouts.Place this below the 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.
Upvotes: -3
Reputation: 1001
Instead of Activities, Use different fragments in Main Activity and set banner at bottom of the Main Activity View, so that fragments would be called instead of Activities and your banner would be same. Set your different activity layout into different fragments.
Follow this link : Android Fragments
Upvotes: 5