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

查看:17
本文介绍了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;

创建:

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;
        }
    }
}

catch 没有捕捉到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

我不知道最后两行是否与这次崩溃有关,但第一行是肯定的.

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天全站免登陆