android:admob InterstitialAd在loadAd时崩溃
作者:互联网
我正在使用Admob的InterstitialAd.我的应用仅在首次调用时就在“ loadAd”处崩溃,并且无法重现(发生在100-200次运行中的次数更少或更多).广告单元ID肯定是正确的.因此,如果loadAd在第一次调用时没有失败,则在此运行时也不会失败.
班级成员:
InterstitialAd mInterstitialAd;
的onCreate:
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getResources().getString(R.string.interstitial_ad_unit_id));
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
requestNewInterstitial();
finish();
}
});
requestNewInterstitial();
requestNewInterstitial方法:
private void requestNewInterstitial() {
if (mInterstitialAd != null) {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(getResources().getString(R.string.test_device))
.build();
if (adRequest == null) {
return;
}
// HERE'S THE CRASH
try {
mInterstitialAd.loadAd(adRequest);
}catch(Exception e) {
return;
}
}
}
抓不到抓“ loadAd”的崩溃.
如何捕获它或至少导致它不会崩溃我的应用程序?我希望当loadAd失败时,不会显示任何广告.
logcat的:
A/libc: Fatal signal 5 (SIGTRAP), code 1 in tid 27794 (AdWorker(Defaul)
W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
我不知道最后两行是否与这次崩溃有关,但是第一行是肯定的.
解决方法:
有时会发生什么事,广告确实会加载到缓冲区中,因此当您尝试调用loadAd时,它会崩溃
的onCreate:
mInterstitialAd = new InterstitialAd(this);
// set the ad unit ID
mInterstitialAd.setAdUnitId(getString(R.string.ad_id));
AdRequest adRequest2 = new AdRequest.Builder()
.build();
// Load ads into Interstitial Ads
mInterstitialAd.loadAd(adRequest2);
mInterstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {
showInterstitial();
}
});
在同一个班:
private void showInterstitial() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
标签:interstitial,android,admob,crash 来源: https://codeday.me/bug/20191010/1885109.html