问题描述
我展示插页式广告,当用户presses回退出应用程序:
I am displaying an interstitial ad when the user presses back to exit the application:
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
}
}
这是我从我的用户收到的崩溃报告:
This is the crash report I received from my users:
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.onBack pressed()
推荐答案
您不能调用 onBack pressed()
当你的活动被暂停。但是,上一回preSS的行为是离开活动。只需拨打完成()
而不是 onBack pressed()
。
You can't call onBackPressed()
when your activity is paused. However, the behavior on a back press is to leave the activity. Just call finish()
instead of onBackPressed()
.
您应该确保在你的 onBack pressed()
的覆盖,该活动将完成。背面可以pssed其他原因$ P $
You should make sure in your onBackPressed()
's override that the activity is going to finish. Back can be pressed for other reasons.
这篇关于无法在super.onBack pressed的onSaveInstanceState执行后,这个动作()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!