问题
when is the "best moment" to load a new ad from AdMob?
I'm programming a shopping list application that has an admob banner on its main screen.
First I called
m_AdView.loadAd(new AdRequest());
in the the onCreate() method. But so I always got displayed the same ad.
Now I want to put the call into onResume(). But isn't there the chance to cause too much network traffic?
回答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:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setContentView(R.layout.detail);
AdView adView = (AdView)this.findViewById(R.id.adView2);
AdRequest re = new AdRequest();
adView.loadAd(re);
...
回答2:
the official documentation tells to put the loadAd() into onCreate(), since you also have to register AdActivity in your manifest:
<activity android: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.
回答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
来源:https://stackoverflow.com/questions/11991176/android-admob-when-to-call-adview-loadad