当用户按下退出应用程序时,我正在显示一个插页式广告:
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
onBackPressed(); //line 98
}
});
requestNewInterstitial();
private void requestNewInterstitial() {
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
}
@Override
public void onBackPressed() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
super.onBackPressed(); //line 410
}
}
这是我从用户那里收到的崩溃报告:
java.lang.RuntimeException: Unable to pause activity {com.myapp/com.google.android.gms.ads.AdActivity}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3088)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3043)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3021)
at android.app.ActivityThread.access$1000(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1253)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5045)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1323)
at android.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:493)
at android.app.Activity.onBackPressed(Activity.java:2215)
at com.myapp.MainActivity.onBackPressed(MainActivity.java:410)
at com.myapp.MainActivity$1.onAdClosed(MainActivity.java:98)
at com.google.android.gms.ads.internal.client.zzc.onAdClosed(Unknown Source)
at com.google.android.gms.ads.internal.client.zzm$zza.onTransact(Unknown Source)
at android.os.Binder.transact(Binder.java:361)
at com.google.android.gms.ads.internal.client.l.a(SourceFile:109)
at com.google.android.gms.ads.internal.a.n(SourceFile:645)
at com.google.android.gms.ads.internal.b.t(SourceFile:351)
at com.google.android.gms.ads.internal.t.t(SourceFile:141)
at com.google.android.gms.ads.internal.overlay.ab.n(SourceFile:672)
at com.google.android.gms.ads.internal.overlay.ab.i(SourceFile:408)
at com.google.android.gms.ads.internal.overlay.a.d.onTransact(SourceFile:86)
at android.os.Binder.transact(Binder.java:361)
at com.google.android.gms.internal.zzdj$zza$zza.onPause(Unknown Source)
at com.google.android.gms.ads.AdActivity.onPause(Unknown Source)
at android.app.Activity.performPause(Activity.java:5335)
at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1233)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3074)
我知道它是在用户关闭广告时触发的,但为什么它会死掉super.onBackPressed()
?