我无法执行Fragment popBackStack来清除我的Child Fragment

时间:2013-10-11 10:56:38

标签: android android-fragments android-fragmentactivity

你好我从我的Activity的onNewIntent方法执行Fragment popBackStack时遇到异常。

以下是我的应用程序崩溃日志。

10-11 16:08:49.750: E/AndroidRuntime(13831): FATAL EXCEPTION: main
10-11 16:08:49.750: E/AndroidRuntime(13831): java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
10-11 16:08:49.750: E/AndroidRuntime(13831):    at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1327)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1338)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at android.support.v4.app.FragmentManagerImpl.popBackStack(FragmentManager.java:466)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at com.xxx.view.DataSend.sendToBackFragment(DataSend.java:850)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at com.xxx.view.MyOneFragmentHolder.clearFragmentBackStack(MyOneFragmentHolder.java:117)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at com.xxx.view.MyOneFragmentHolder.clearBackStack(MyOneFragmentHolder.java:131)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at com.xxx.view.CustomTabsActivity.onNewIntent(CustomTabsActivity.java:1537)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1119)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:1726)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at android.app.ActivityThread.performNewIntents(ActivityThread.java:1738)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at android.app.ActivityThread.handleNewIntent(ActivityThread.java:1746)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at android.app.ActivityThread.access$2300(ActivityThread.java:117)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:982)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at android.os.Looper.loop(Looper.java:130)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at android.app.ActivityThread.main(ActivityThread.java:3687)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at java.lang.reflect.Method.invokeNative(Native Method)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at java.lang.reflect.Method.invoke(Method.java:507)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
10-11 16:08:49.750: E/AndroidRuntime(13831):    at dalvik.system.NativeStart.main(Native Method)

现在这里是FragmentActivity中的Fragment层次结构。

  1. my FragmentActivity包含一个ViewPager
  2. 现在我的ViewPager包含五个片段。
  3. 在该五个片段的第二个片段中,第三个片段包含以下逻辑的嵌套片段。
    1. 我使用FrameLayout加载简单的Fragment然后在其中执行我的真实片段,当用户单击该片段的列表项时,它将再次在此Framelayout中加载Fragment。
  4. 所以我的Activity onNewIntent为我的ViewPager第二个Fragment执行popBackStack,它作为容器工作。

1 个答案:

答案 0 :(得分:0)

首先,当我在另一个片段中使用片段时,我经历了很多问题(通常不是一个好习惯) 阅读此answer它可能会对您有所帮助。 堆栈跟踪说你试图在调用saveInstanceState方法后弹出堆栈,你没有提供任何代码,但我认为你不能在应用程序保存其实例并且很可能已经停止/被销毁后使用它

干杯 MAC