0

我想在我的 Android 应用中使用插页式广告。但我希望它每 10 分钟出现一次,因为在我的应用程序中没有暂停或关卡。一旦用户登录将持续观看数小时。

4

1 回答 1

0

使用处理程序。在 int delay=15000 计算并给出 10 分钟的延迟

  Handler h = new Handler();
int delay = 15000; //15 seconds
Runnable runnable;
@Override
protected void onStart() {
 //start handler as activity become visible

    h.postDelayed(new Runnable() {
        public void run() {
            //do something
      // Show your Admob Ad here and Refetch the ad else it wont be shown second time

    if (admnbInterstetial.isLoaded()) {
        admnbInterstetial.show();
    }
   AdRequest adRequest1 = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
            admnbInterstetial.loadAd(adRequest1);


            runnable=this;

            h.postDelayed(runnable, delay);
        }
    }, delay);

    super.onStart();
}

@Override
protected void onPause() {
    h.removeCallbacks(runnable); //stop handler when activity not visible
    super.onPause();
}

这应该可以解决问题

于 2016-12-22T05:27:26.147 回答