Admob on Multiple Activities?

前端 未结 2 668
醉酒成梦
醉酒成梦 2020-12-03 05:53

I have 7 Activities in my application. I wants to display admob in every activity

Whether i have to create each AdView in every activity?

2条回答
  •  长情又很酷
    2020-12-03 06:32

    In my app I have a cache of 0..12 ads at any given time. I'm reusing them accross different Fragments in an endless ViewPager. The caching class is in charge of loading the providing the ads to the Fragments.

    The trick is to:

    1. Call the AdView's onDestory only when you're sure you're done with that AdView instance for good. This means that the Fragments themselves are not in charge of this.

    2. Passing the AdView's themselves between the Fragments, we need to remember to detach each AdView from its hierarchy:

    (only on the UI thread of course):

    public void detachFromHirerchy() 
    {
        View adView = getAdView();
        if ( adView != null )
        {
            ViewGroup parent = (ViewGroup) adView.getParent();
            if (parent != null) 
            {
                parent.removeView( adView );
            }
        }
    
    }
    

提交回复
热议问题