android:admob InterstitialAd在loadAd时崩溃 [英] android: admob InterstitialAd crash at loadAd

查看:284
本文介绍了android:admob InterstitialAd在loadAd时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Admob的InterstitialAd。我的应用仅在首次调用时就在 loadAd上崩溃,并且无法重现(发生在100-200次运行中的次数更少或更多)。广告单元ID肯定是正确的。因此,如果loadAd在第一次调用时没有失败,则在此运行时也不会失败。

I'm using InterstitialAd by Admob. My app crashes at "loadAd" only in the first time it's called, and it's not reproducible (it happens once in 100-200 runs less or more). the ad unit id is correct for sure. So if loadAd doesn't fail in the first time it's called, it won't fail at all at this run.

类成员:

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方法:

requestNewInterstitial method:

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崩溃。

The catch doesn't catch the crash of "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

的不受支持的配置文件4我不知道最后两行与这次崩溃有关,但第一个是肯定的。

I don't know if the last 2 lines are about this crash but the first one is for sure.

推荐答案

Activtiy_m1.java

public class Activity_m1 extends AppCompatActivity {

    InterstitialAd interstitial;
    Activity mactivity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_m1);
        setTitle("ABCD");
        Advertise.displaym1(getApplicationContext());
    }

    @Override
    public void onBackPressed() {
            Advertise adv = new Advertise();
            adv.disp_adm1();
        finish();
    }
}

Advertise.java

public class Advertise {
    public static InterstitialAd interstitial;

    public static void displaym1(Context act) {
        interstitial = new InterstitialAd(act);
        interstitial.setAdUnitId("ca-app-pub-2621588945556564/3343556333");
        AdRequest adRequest1 = new AdRequest.Builder().build();
        interstitial.loadAd(adRequest1);
    }
    public void disp_adm1() {
        if (interstitial.isLoaded())
            interstitial.show();
    }
}

这篇关于android:admob InterstitialAd在loadAd时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆