跳至主要内容

博文

目前显示的是 十月, 2017的博文

admob设置广告请求时间 for Android

您应该将您的admob生命周期附加到您的活动生命周期,以便您的应用程序对用户可见时,您可以开始/停止显示添加。 为您创建广告和处理程序的全局变量 private InterstitialAd mInterstitialAd; private Handler mHandler = new Handler(); private Runnable mRunnable = new Runnable() { @Override public void run() { // Wait 60 seconds mHandler.postDelayed(this, 60*1000); // Show Ad showInterstitial(); } }; 然后 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Create the InterstitialAd and set the adUnitId mInterstitialAd = newInterstitialAd(); loadInterstitial(); } @Override protected void onStart() { super.onStart(); // Start showing Ad in every 60 seconds //when activity is visible to the user mHandler = new Handler(); //mHandler.post(mRunnable); // Run first add after 20 seconds mHandler.postDelayed(mRunnable,20*1000); } protected void onStop() { super.onStop();