按下首页或菜单按钮时如何暂停插页式广告

时间:2018-11-01 14:39:32

标签: java android admob ads interstitial

我正在使用Scheduler每60秒显示1个插页式广告。但是问题在于,当用户按“主页”或“菜单”按钮或最小化应用程序,或通过按“返回”按钮退出应用程序时,插页式广告仍在显示。我想在应用程序最小化时暂停广告。谁能帮忙....!请...

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();
}

}

0 个答案:

没有答案