java.lang.IllegalStateException求指導(dǎo) 財(cái)富值46

科技 未結(jié) 6 733
M25****282
M25****282 2022-09-06 16:21

測(cè)試同學(xué)跑Monkey跑出了這個(gè)異常導(dǎo)致的crash,對(duì)應(yīng)的Android版本是Android6.0。
補(bǔ)充:出問(wèn)題的Activity是使用了ViewPager無(wú)限循環(huán)展示圖片,內(nèi)容是ImageView,不是Fragment。
但是我的應(yīng)用中沒(méi)有用到任何Fragment,任何commit方法。詳細(xì)Log如下:

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1438) at android.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:581) at android.app.Activity.onBackPressed(Activity.java:2537) at android.app.Activity.onKeyUp(Activity.java:2511) at android.view.KeyEvent.dispatch(KeyEvent.java:2695) at android.app.Activity.dispatchKeyEvent(Activity.java:2764) at com.android.internal.policy.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2384) at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4687) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4643) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4155) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4208) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4174) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4320) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4182) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4377) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4155) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4208) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4174) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4182) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4155) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4208) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4174) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4353) at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4523) at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2336) at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1940) at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1931) at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2313) at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:328) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:5811) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:734)

在StackOverFlow上搜到了類(lèi)似的問(wèn)題:http://stackoverflow.com/ques...

StackOverFlow上說(shuō)要重寫(xiě)onSaveInstaceState方法,去掉super調(diào)用,但是我不清楚這樣做是否存在負(fù)作用,所以希望有經(jīng)驗(yàn)的人指導(dǎo)一下如何解決這個(gè)問(wèn)題。

6條回答
  •  fgh54574
    fgh54574 (樓主)
    2022-09-06 16:36

    方案二(參考StackOverFlow上的做法)——重寫(xiě)onSaveInstanceState方法:

提交回復(fù)