Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to preload AdMob ads on Android?

I have a AdMob ad in a "dialog" (a View I created to look like one, because ads will not fit in a normal Dialog) in my app. Usually it takes about 4 or 5 seconds before the ad loads, and since it's in a "dialog," the user will most likely click a button (closing the dialog) before the ad loads.
Is there a way I can preload the ads so that they will show as soon as their containing View is created?

like image 509
Marcus Avatar asked Nov 04 '22 20:11

Marcus


2 Answers

I have done it by use one adview multiple time and in multiple activity

It just load once, and you can use it where ever you want,

It will refresh on its given refresh rate.

demo is given here

you may need some modification but actual idea is implemented.

like image 99
RBK Avatar answered Nov 15 '22 01:11

RBK


First in another persistent context, you create AdView of admob and load ad with AdRequest.

And then, add the AdView in 'onCreateView' of DialogFragment. Make sure the AdView is removed from previous parent view.

if (adView.getParent() != null) {
    ((ViewGroup) adView.getParent()).removeView(adView);
}

// Add the banner ad to the ad view.
adCardView.addView(adView);
like image 22
Brownsoo Han Avatar answered Nov 15 '22 01:11

Brownsoo Han