我正在用libgdx开发一个简单的游戏。在整合AdMob插页式广告期间,我遇到了令人不快的问题。以下是在AndroidApplication的onCreate方法中加载广告的代码:
interstitialAd = new InterstitialAd(getApplication());
interstitialAd.setAdUnitId(INTERSTITIAL_AD_UNIT_ID);
AdRequest.Builder builder = new AdRequest.Builder();
AdRequest ad = builder.build();
try {
interstitialAd.loadAd(ad);
}
catch (Exception e){
e.printStackTrace();
}
所以一旦“interstitialAd.loadAd(ad);”发生了我的游戏开始滞后,logcat显示大量的“GC_FOR_ALLOC释放”消息:
08-29 13:39:14.965 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1029K, 18% free 15491K/18880K, paused 59ms, total 59ms
08-29 13:39:14.965 29994-29994/com.a1.runner.android D/WebView﹕ loadUrlImpl: called
08-29 13:39:14.995 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1029K, 18% free 15493K/18880K, paused 30ms, total 30ms
08-29 13:39:14.995 29994-30245/com.a1.runner.android D/webcore﹕ CORE loadUrl: called
08-29 13:39:14.995 29994-30245/com.a1.runner.android D/webkit﹕ Firewall not null
08-29 13:39:14.995 29994-30245/com.a1.runner.android D/webkit﹕ euler: isUrlBlocked = false
08-29 13:39:15.030 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1028K, 18% free 15491K/18880K, paused 31ms, total 31ms
08-29 13:39:15.060 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 31ms, total 31ms
08-29 13:39:15.095 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 31ms, total 31ms
08-29 13:39:15.125 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 30ms, total 30ms
08-29 13:39:15.155 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 30ms, total 30ms
08-29 13:39:15.185 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 29ms, total 29ms
08-29 13:39:16.290 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 60ms, total 60ms
08-29 13:39:16.295 29994-29994/com.a1.runner.android D/WebView﹕ loadUrlImpl: called
08-29 13:39:16.330 29994-30245/com.a1.runner.android D/webcore﹕ CORE loadUrl: called
08-29 13:39:16.330 29994-30245/com.a1.runner.android D/webkit﹕ Firewall not null
08-29 13:39:16.330 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1030K, 18% free 15494K/18880K, paused 35ms, total 35ms
08-29 13:39:16.330 29994-30245/com.a1.runner.android D/webkit﹕ euler: isUrlBlocked = false
08-29 13:39:16.365 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1027K, 18% free 15491K/18880K, paused 29ms, total 29ms
08-29 13:39:16.395 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 30ms, total 30ms
08-29 13:39:16.425 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 30ms, total 30ms
08-29 13:39:16.455 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 30ms, total 30ms
08-29 13:39:16.490 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 30ms, total 31ms
08-29 13:39:16.520 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 31ms, total 31ms
08-29 13:39:17.600 29994-29994/com.a1.runner.android D/WebView﹕ loadUrlImpl: called
08-29 13:39:17.600 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1029K, 18% free 15493K/18880K, paused 35ms, total 35ms
08-29 13:39:17.600 29994-30245/com.a1.runner.android D/webcore﹕ CORE loadUrl: called
08-29 13:39:17.600 29994-30245/com.a1.runner.android D/webkit﹕ Firewall not null
08-29 13:39:17.600 29994-30245/com.a1.runner.android D/webkit﹕ euler: isUrlBlocked = false
08-29 13:39:17.635 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1028K, 18% free 15491K/18880K, paused 32ms, total 32ms
08-29 13:39:17.665 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 30ms, total 30ms
08-29 13:39:17.695 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 30ms, total 30ms
08-29 13:39:17.730 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 29ms, total 30ms
08-29 13:39:17.760 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 30ms, total 30ms
08-29 13:39:17.790 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 29ms, total 29ms
08-29 13:39:17.820 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 29ms, total 29ms
08-29 13:39:19.060 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 62ms, total 62ms
08-29 13:39:19.090 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1024K, 18% free 15491K/18880K, paused 30ms, total 31ms
08-29 13:39:19.095 29994-29994/com.a1.runner.android D/WebView﹕ loadUrlImpl: called
08-29 13:39:19.125 29994-30245/com.a1.runner.android D/webcore﹕ CORE loadUrl: called
08-29 13:39:19.125 29994-32552/com.a1.runner.android D/dalvikvm﹕ GC_FOR_ALLOC freed 1029K, 18% free 15493K/18880K, paused 33ms, total 33ms
几秒钟后,这些消息停止显示,游戏开始顺利播放。如果要评论“interstitialAd.loadAd(ad);”然后游戏也顺利进行。我使用com.google.android.gms:play-services-ads:7.3.0
UPD。注意到包含视频的广告会发生这种情况。