Android & AdMob: When to call AdView.loadAd

好久不见. 提交于 2021-01-27 21:30:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!