4

Hello I am having a problem trying to stop adMob from requesting new ads. If a person hits the back key or home the application goes to sleep, but admob continues to request new ads. The only way it stops is if the user selects quit from the menu.

Does anyone know of a way that in my onPause method I could do something such as ad.pauseUpdates(); I am not seeing anything like this in the documentation.

Any ideas would be helpful.

Janusz
  • 187,060
  • 113
  • 301
  • 369
JMazApps
  • 41
  • 3
  • What do you do when the user selects quit from the menu? – Cheryl Simon Sep 21 '10 at 01:00
  • I just do a super.finish(); and that takes takes care of getting rid of the application. That works and the requests stop. In the pause it continues updating. – JMazApps Sep 21 '10 at 01:09
  • 1
    I think I have solved it. It appears that the reason it was still requesting ads is because I had to override the onPause and onStop methods. I don't understand why that made a difference, I simply call super.onPause/onStop which should be done automatically without overriding it I thought? Either way it appears to work. If you could tell me why that makes a difference that would be awesome! Thanks! – JMazApps Sep 21 '10 at 02:00
  • why do you worry about that? your app is getting ad impressions without user seeing the ad :-). And anyway it is an issue in AdMob SDK. – bhups Sep 21 '10 at 03:57
  • 1
    I wouldn't have worried if I was getting paid for impressions. But unfortunately you only get paid per click. With it receiving impressions without a user seeing the application it was simply wasting battery life for users (ad request) and dropping my earning statistics. I figured it was a problem with adMob but it appears that this has fixed the issue... I hope lol – JMazApps Sep 21 '10 at 04:31
  • super methods are NEVER called automatically! – escape-llc Nov 17 '16 at 13:32

1 Answers1

1

You can do that:

public class BannerSample extends Activity {
/** The view to show the ad. */
  private AdView adView;    

  /* Your ad unit id. Replace with your actual ad unit id. */
  private static final String AD_UNIT_ID = "INSERT_YOUR_AD_UNIT_ID_HERE";

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);

// Add the AdView to the view hierarchy. The view will have no size
// until the ad is loaded.
LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
layout.addView(adView);

// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
    .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
    .build();

// Start loading the ad in the background.
adView.loadAd(adRequest);
  }

  @Override
  public void onResume() {
    super.onResume();
    if (adView != null) {
      adView.resume();
    }
  }

  @Override
  public void onPause() {
    if (adView != null) {
      adView.pause();
}
super.onPause();
  }

/** Called before the activity is destroyed. */
  @Override
  public void onDestroy() {
// Destroy the AdView.
 if (adView != null) {
  adView.destroy();
  }
 super.onDestroy();
}
  }
mostafa_zakaria
  • 116
  • 1
  • 6