我正在从服务器获取推送通知时从sqlite更新我的片段,当我在同一个片段上更新时。但当我在另一个活动并获得推送通知时,我的应用程序崩溃了。
这是我的例外:
03-28 22:18:03.302: E/AndroidRuntime(17631): FATAL EXCEPTION: main
03-28 22:18:03.302: E/AndroidRuntime(17631): Process: com.newt.vdsi.driver, PID: 17631
03-28 22:18:03.302: E/AndroidRuntime(17631): java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
03-28 22:18:03.302: E/AndroidRuntime(17631): at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1360)
03-28 22:18:03.302: E/AndroidRuntime(17631): at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1378)
03-28 22:18:03.302: E/AndroidRuntime(17631): at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
03-28 22:18:03.302: E/AndroidRuntime(17631): at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)
03-28 22:18:03.302: E/AndroidRuntime(17631): at com.newt.vdsi.driver.Home$1.onReceive(Home.java:517)
03-28 22:18:03.302: E/AndroidRuntime(17631): at android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:297)
03-28 22:18:03.302: E/AndroidRuntime(17631): at android.support.v4.content.LocalBroadcastManager.access$000(LocalBroadcastManager.java:46)
03-28 22:18:03.302: E/AndroidRuntime(17631): at android.support.v4.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:116)
03-28 22:18:03.302: E/AndroidRuntime(17631): at android.os.Handler.dispatchMessage(Handler.java:102)
03-28 22:18:03.302: E/AndroidRuntime(17631): at android.os.Looper.loop(Looper.java:136)
03-28 22:18:03.302: E/AndroidRuntime(17631): at android.app.ActivityThread.main(ActivityThread.java:5086)
03-28 22:18:03.302: E/AndroidRuntime(17631): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 22:18:03.302: E/AndroidRuntime(17631): at java.lang.reflect.Method.invoke(Method.java:515)
03-28 22:18:03.302: E/AndroidRuntime(17631): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
03-28 22:18:03.302: E/AndroidRuntime(17631): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
03-28 22:18:03.302: E/AndroidRuntime(17631): at dalvik.system.NativeStart.main(Native Method)
提前感谢。
答案 0 :(得分:1)
这通常发生在该片段的主机活动已执行onStop()并且在FragmentTransaction上调用commit()之后(即调用commit并且隐藏主机活动时)。
在收到推送通知时尝试使用带有自定义意图过滤器的本地广播,并在片段中使用广播接收器作为更新逻辑。
在这种情况下,如果片段在推送通知发生时可见,则会更新,否则让其onCreateView()处理逻辑。