您好,当我从 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 层次结构。
- 我的 FragmentActivity 包含一个 ViewPager
- 现在我的 ViewPager 包含五个 Fragment 。
- 在这五个片段的第二个片段中,第三个片段按以下逻辑包含嵌套片段。
- 我已经使用 FrameLayout 加载了简单的 Fragment,然后在其中执行我的真实 Fragment,当用户单击该片段的列表项时,它将再次在此 Framelayout 中加载 Fragment。
所以我的 Activity onNewIntent 为我的 ViewPager 第二个 Fragment 执行 popBackStack,它作为容器工作。