我的应用在许多 Android 平台(4.1、4.0.4、2.3.6...)上不断报告此问题。但我无法在手机上重现此问题。我已经通过谷歌搜索了这个问题,但堆栈跟踪似乎与我的不一样。
有人知道这个问题是怎么发生的吗?以及如何预防?或者我怎样才能重现这个错误?谢谢你。
堆栈跟踪:
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1327)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1338)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)
at android.support.v4.app.FragmentTabHost.onAttachedToWindow(FragmentTabHost.java:278)
at android.view.View.dispatchAttachedToWindow(View.java:12064)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2707)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2714)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2714)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2714)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2714)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1339)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1131)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4611)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
at dalvik.system.NativeStart.main(Native Method)
- - - - - - - - - - 编辑 - - - - - - - - - -
对乔纳森:
我有两个片段。并且只有一个片段覆盖了onPause
回调,代码如下。而且我不会在onPause
. 我覆盖的另一个回调是onResume
回调,代码如下。
分段:
@Override
public void onPause() {
super.onPause();
if (mView instanceof MyView) {
MyView my = (MyView) mView;
my.onPause();
}
}
@Override
public void onResume() {
super.onResume();
if (mView instanceof MyView) {
MyView my = (MyView) mView;
my.onResume();
}
}
我的观点:
public void onPause() {
pause = true;
}
public void onResume() {
pause = false;
if (mDialog != null && mDialog.isShowing()) {
mDialog.dismiss();
mDialog = null;
}
}
我还跟踪了FragmentActivity
/的代码FragmentManager
,似乎如果onAttachedToWindow()
之前调用过onPostResume()
,那么问题就会发生。有可能onAttachedToWindow()
之前被调用onPostResume()
吗?