Search code examples
androidadmobondestroy

Admob ads adding to previous screen when using back button?


Just installed admob tonight and works fine except for one issue. When using the back button, the ads add to the main screen or last page your were on. Lets see if I can explain. When app is open it has one ad showing I visit a list menu item then hit the back button it adds one ad to the page I was just on, now I have two. Do it again now have three..... etc. It will continue to do it until the screen is full. Reopen the app it starts at one again. I refresh the screen it reverts to one again. Being a new not sure what you would want from me to help solve this issue, but please ask.

I would assume this would have something to do with it?

//onDestroy
@Override
public void onDestroy() {
    adView.destroy();
    super.onDestroy();
    //BT_debugger.showIt(activityName + ":onDestroy");  
}

Android 3.2 GoogleAdMobAdsSdk-4.3.1.jar

Thank you in advance.


Solution

  • You have this:

    //onResume
    @Override 
    public void onResume() { 
        super.onResume(); 
        //BT_debugger.showIt(activityName + ":onResume"); 
        // Create Admob View 
        adView = new AdView(this, AdSize.BANNER, Config.ADMOB_PUBLISHER_ID); 
        // Lookup LinearLayout 
        LinearLayout layout = (LinearLayout)findViewById(R.id.admob_main); 
        // Add the adView to it 
        layout.addView(adView); 
        // Initiate a generic request to load it with an ad 
        adView.loadAd(new AdRequest()); 
    } 
    

    Move these lines to the the onCreate Method and delete them from the onResume

    adView = new AdView(this, AdSize.BANNER, Config.ADMOB_PUBLISHER_ID); 
    // Lookup LinearLayout 
    LinearLayout layout = (LinearLayout)findViewById(R.id.admob_main); 
    // Add the adView to it 
    layout.addView(adView); 
    // Initiate a generic request to load it with an ad 
    adView.loadAd(new AdRequest());