Android & Admob: When To Call Adview.loadad
Solution 1:
The best place to load the adMob
is in the onCreate()
. So, I would just leave it in the onCreate()
method. Don't worry about what ad is being displayed as it is what the adMob api is telling it to display. It may be in testing mode, so when you go to run it "live", it will change. The fact that you are getting an ad means it is working.
Here is what I did with my app:
@OverrideprotectedvoidonCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setContentView(R.layout.detail);
AdViewadView= (AdView)this.findViewById(R.id.adView2);
AdRequestre=newAdRequest();
adView.loadAd(re);
...
Solution 2:
the official documentation tells to put the loadAd() into onCreate(), since you also have to register AdActivity in your manifest:
<activityandroid:name="com.google.android.gms.ads.AdActivity"android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode"/>
I guess it will stick to the lifecycle of your main activity hence handling onPause() and onResume() properly.
EDIT
According to admob sample you have to delegate lifecycles calls to AdView instance.
Solution 3:
Wondering the same (talking about Banner not Interstitial )
Most examples I found on the net
load the request (adView.loadAd(new AdRequest())
) in onCreate
.
but can be onStart
:
public void onStart() {
super.onStart();
if(adView != null) {
adView.loadAd(new AdRequest());
}
according: AdMob ad in onCreate OK, but disappears if you return to activity, why?
In Activity life cycle, OnStart
is called just after onCreate
https://developer.android.com/guide/components/activities/activity-lifecycle.html
so... I thing sound good place too
Post a Comment for "Android & Admob: When To Call Adview.loadad"