Prevent AdView from being recreated for every action

I have the following in all my actions:

<com.google.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" ads:adUnitId="..." ads:adSize="BANNER" ads:testDevices="TEST_EMULATOR" ads:loadAdOnCreate="true" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true"/> 

The problem is that it reloads the ad every time I switch between actions, so there is a short period of time when the ad does not appear. Some applications do not have this problem, for example, Bubble Shoot: when switching between actions, the ad does not disappear at all.

How can I achieve this effect? I tried setting loadAdOnCreate="false" and using the global AdRequest , but it still seems to recreate the actual control, so there is still a (very short but noticeable) period when the ad is not showing.

Note: I need it to work for all API levels> = 7 ideally. If this is not possible,> = Android 2.3 / API level 9 is also acceptable. It also does not depend on the type of device and screen size.

+6
source share
1 answer

Are you sure the bubble arrow uses actions? Maybe they use fragments for different screens and save the ad in one activity or fragment?

You can use android compatibility pack to get support from level 4 api: http://developer.android.com/tools/extras/support-library.html

You will have to handle the navigation manually by overriding onBackPressed() and using the FragmentManager . This is a bit of a learning curve, but fragments can be very good to work as soon as you hang it :)

+1
source

Source: https://habr.com/ru/post/924033/


All Articles