I am using Scheduler to show 1 interstitial ad after every 60 seconds. But the problem is when user press Home or Menu button or minimize the app, or exit app by pressing back button the Interstitial ads are still displaying. I want to pause ads when application is minimized. Can anyone help....! please...
private InterstitialAd mInterstitialAd;
prepareAd();
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(new Runnable() {
public void run() {
Log.i("hello", "world");
runOnUiThread(new Runnable() {
public void run() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Log.d("TAG", " Interstitial not loaded");
}
prepareAd();
}
});
}
}, 1, 60, TimeUnit.SECONDS);
}
public void prepareAd() {
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.interstitial));
mInterstitialAd.loadAd(new AdRequest.Builder().build());
onPause();
}
}