user2599233
user2599233

Reputation:

Show a constant admob ad banner in all the activities

I am working on an android application, i have embedded admob ad at the bottom of each activity and its shows ad in all activities, but i want to show a constant admob ad in all the activities that displays all the time without destroy itself during switching activities, please help me if any one know the solution for this problem, i have 3 activities and i also try to create a base class and extends all activities with this base class and call the function which creates and load the ad, but still the same issue i have to call this function from every activity class so every time it sends request to load ad and display just on the desire activity from which it calls, i need to show a one ad on all the three activities, thanx in advance....

Upvotes: 2

Views: 2563

Answers (3)

Abdul Wasae
Abdul Wasae

Reputation: 3688

There may be one way to do this. But for that, you might need to completely restructure your app UI. You could keep one activity in your app, and convert all the actual activities into fragments. Then, you will just swap fragments inside the same single activity. I wouldn't recommend this though.

Upvotes: 1

Swayaparihara
Swayaparihara

Reputation: 81

Not sure if this will help you. Give this code a try. Also, if required, try using the child fragment approach to View Pager.

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


    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer"
        android:layout_width="match_parent"
        android:fitsSystemWindows="true"
        android:layout_height="match_parent"
        android:layout_marginBottom="50dp">

        <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:orientation="vertical">


            <include android:id="@+id/toolbar_actionbar"     layout="@layout/toolbar_default"
                android:layout_width="match_parent" android:layout_height="wrap_content" />

            <FrameLayout android:id="@+id/container21" android:layout_width="match_parent"
                android:clickable="true" android:layout_height="match_parent" />
        </LinearLayout>

        < com.myapp.isgreat.ScrimInsetsFrameLayout android:id="@+id/scrimInsetsFrameLayout"
            android:layout_width="@dimen/navigation_drawer_width" android:layout_height="wrap_content"
            android:fitsSystemWindows="true" android:layout_gravity="start" app:insetForeground="#4000"
            android:elevation="10dp">
            <fragment android:id="@+id/fragment_drawer"
                android:name="com.my.appisgreat.NavigationDrawerFragment"
                android:layout_width="@dimen/navigation_drawer_width"
                android:layout_height="match_parent" android:fitsSystemWindows="true"
                app:layout="@layout/fragment_navigation_drawer"
                tools:layout="@layout/fragment_navigation_drawer" />
        </com.myapp.isgreat.ScrimInsetsFrameLayout>


    </android.support.v4.widget.DrawerLayout>
    <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="@string/banner_ad_unit_id">
    </com.google.android.gms.ads.AdView>

    </RelativeLayout>

Hope this helps..! Happy Android development.!

Upvotes: 1

William
William

Reputation: 20196

There is no way to do this. And as Ellis says you only want to display an ad where your user spends most of their time.

Upvotes: 1

Related Questions