Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 即使在关闭应用程序后仍显示AdMob间隙广告_Android_Android Studio_Firebase_Admob_Interstitial - Fatal编程技术网

Android 即使在关闭应用程序后仍显示AdMob间隙广告

Android 即使在关闭应用程序后仍显示AdMob间隙广告,android,android-studio,firebase,admob,interstitial,Android,Android Studio,Firebase,Admob,Interstitial,我正在制作android应用程序,AdMob集成在我的应用程序中,我正在使用AdMob在WebView加载20秒后显示广告。问题是,当用户在20秒前关闭应用程序时,间隙广告仍会显示,这违反了google AdMob的政策,我如何确保当用户退出活动或应用程序时,间隙广告不应显示 这是我的代码: new Handler().postDelayed(new Runnable() { @Override public void run() { interAd = n

我正在制作android应用程序,AdMob集成在我的应用程序中,我正在使用AdMob在WebView加载20秒后显示广告。问题是,当用户在20秒前关闭应用程序时,间隙广告仍会显示,这违反了google AdMob的政策,我如何确保当用户退出活动或应用程序时,间隙广告不应显示

这是我的代码:

new Handler().postDelayed(new Runnable() {
     @Override
     public void run() {
         interAd = new InterstitialAd(MainActivity.this);
         interAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
         AdRequest adRequest = new AdRequest.Builder()
                 .addTestDevice("SEE_YOUR_LOGCAT_TO_GET_YOUR_DEVICE_ID")
                 .build();
         interAd.loadAd(adRequest);
         interAd.setAdListener(new AdListener() {
                @Override
                public void onAdLoaded() {
                    interAd.show();
         }
     });

     interAd.setAdListener(new AdListener() {
         @Override
        public void onAdClosed() {
            // Code to be executed when the interstitial ad is closed.
             Log.i("Ads", "onAdClosed");
            }
        });
    }
} , 20000);

添加onBackpress和onDestroy overides,删除处理程序回调,并在每个回调中将Interstituralad变量设置为null

@Override
protected void onBackpressed() {
    handler.removeCallbacks(your handler name here);
    interAd =null
    super.onBackpressed();
}

@Override
protected void onDestroy() {
    handler.removeCallbacks(your handler name here);
    interAd =null
    super.onDestroy();
}
如果你想在你的应用程序进入后台时也处理这个问题,那么也可以在后台添加暂停

@Override
protected void onPause() {
    handler.removeCallbacks(your handler name here);
    interAd =null
    super.onPause();
 }
希望有帮助


如果您需要进一步的帮助,请告诉我。

当onDestroy呼叫时,请将您的处理程序传递给我

Handler myHandler = new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {

            interAd = new InterstitialAd(MainActivity.this);
            interAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
            AdRequest adRequest = new AdRequest.Builder()
                    .addTestDevice("SEE_YOUR_LOGCAT_TO_GET_YOUR_DEVICE_ID")
                    .build();
            interAd.loadAd(adRequest);
            interAd.setAdListener(new AdListener() {
                @Override

                public void onAdLoaded() {
                   if(interAd.isLoaded() && interAd !=null)
                      interAd.show();
                }
            });

            interAd.setAdListener(new AdListener() {

            @Override
            public void onAdClosed() {
                // Code to be executed when the interstitial ad is closed.
                Log.i("Ads", "onAdClosed");
            }
    });

        }
    } , 20000);



 @Override
    protected void onDestroy() {
        Log.d("MainActivty","onDestroy removing callbacks...");
        handler.removeCallbacks(myHandler);
        interAd =null
        super.onDestroy();

}

不工作错误:不兼容的类型。必需的android.os.handler找到布尔值,我在import alsoinic 3中有android.os.handler,这里有间隙Ads解决方案