Show permanent admob banner ad in all activities

I am working on an android app, I have an inline admob ad at the bottom of each activity and its showing ads in all activities, but I want to show a persistent admob ad in all activities, which are displayed all the time without destructing during a switch, please help me if does anyone know a solution to this problem, I have 3 actions and I am also trying to create a base class and extend all actions with that base class and call a function that creates and loads the ad, but still the same problem, I has to call this function from every activity class, so every time it sends a request to load an ad and only displays the desire activity from which it is calling, I need to show one ad in all 3 activities thanx in advance ...

+1


source to share


3 answers


There is no way to do this. And as Ellis says you want to show ads when your user spends most of their time.



0


source


There may be one way to do this. But to do this, you may need to completely restructure the application's UI. You can keep one activity in your application and convert all actual activities to fragments. Then you just swap fragments inside the same activity. I would not recommend this though.



+1


source


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

    <?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!

0


source







All Articles