jaya prakash jaya prakash - 4 months ago 120
Android Question

How to Single admob ad without refreshing multiple activities in android?

Hi I am new to android app development... And developed android app. In the app I have put admob ad in every activity. When I move one activity to another. Everytime ad is reloading. But I want ad don't reload(same ad displays without reload). Please help me best solution for this and give me a example or sample project...

Answer

I suggest you to use FrameLayout and Fragments with Single Activity instead of multiple Activity for showing your Views. I have similar kind of requirement. i have done like this.

<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"
    android:id="@+id/mainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/adView" />

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:visibility="gone"
        app:adSize="BANNER"
        app:adUnitId="ca-app-pub-xxxxxxxxxx/xxxxxxx" />

</RelativeLayout>

Design all your views as Fragments and Replace fragments in FrameLayout. When Your Activity is shown then Ad is displayed and when you move from screen to screen it will not reloaded.

I hope it helps.

Comments