Java.lang.IllegalStateException活动已被销毁

时间:2015-11-26 10:33:50

标签: android android-fragments android-fragmentactivity fragmentmanager

我知道有很多相同的问题,我检查了它的解决方案\建议。但是,他们不适合我。我正在尝试添加片段,当我调用fragmentTransaction.commit()时,它会抛出异常,但这只发生在我的第二个片段上。

我向我的应用程序发送通知,当它被点击时,它打开我的应用程序打开主片段,那时getSupportFragmentManager().findFragmentById(R.id.rl_content_fragment);为当前片段返回null(应该是正确的),问题是我的第二个片段(playerFragment)当我尝试添加它时(在调试时)我发现getSupportFragmentManager()仍然为当前片段返回null,并且当我调用fragmentTransaction.commit()时它抛出了活动被销毁的异常。

我的问题

1 - 为什么Activity在应用程序启动时被销毁或完成?

2 - 我该如何解决这个问题?

任何提示都将不胜感激,谢谢。 编辑这是我得到的异常,我知道我不应该更改视图,除非我在mainThread上,但我确实在主线程上报告,抱歉忘了说我们正在使用commitAllowingStateLoss()和这就是我得到的

java.lang.IllegalStateException: Activity has been destroyed
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1399)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:637)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:620)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at com.myApp.BaseActivity.addContentFragment(BaseActivity.java:502)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at com.myApp.BaseActivity$3.onCompleted(BaseActivity.java:837)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at com.myAppSDK.Managers.SignalManager.setCompleted(SignalManager.java:291)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at com.myAppSDK.Managers.EpisodeManager$5.onCompleted(EpisodeManager.java:1107)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at com.myAppSDK.Managers.SignalManager.setCompleted(SignalManager.java:291)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at com.myAppSDK.Managers.APIRequestManager$ConnectionTask.onPostExecute(APIRequestManager.java:645)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at com.myAppSDK.Managers.APIRequestManager$ConnectionTask.onPostExecute(APIRequestManager.java:546)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at android.os.AsyncTask.finish(AsyncTask.java:632)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at android.os.AsyncTask.access$600(AsyncTask.java:177)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:136)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5146)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
11-26 12:57:06.464 26608-26608/com.myApp E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)

如果我使用commit(),我会收到此异常

Process: com.myApp, PID: 10659
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1377)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1395)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:637)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:616)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at com.myApp.BaseActivity.addContentFragment(BaseActivity.java:502)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at com.myApp.BaseActivity$3.onCompleted(BaseActivity.java:837)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at com.myAppSDK.Managers.SignalManager.setCompleted(SignalManager.java:291)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at com.myAppSDK.Managers.EpisodeManager$5.onCompleted(EpisodeManager.java:1107)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at com.myAppSDK.Managers.SignalManager.setCompleted(SignalManager.java:291)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at com.myAppSDK.Managers.APIRequestManager$ConnectionTask.onPostExecute(APIRequestManager.java:645)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at com.myAppSDK.Managers.APIRequestManager$ConnectionTask.onPostExecute(APIRequestManager.java:546)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at android.os.AsyncTask.finish(AsyncTask.java:632)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at android.os.AsyncTask.access$600(AsyncTask.java:177)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:136)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5146)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
11-26 12:41:12.529 10659-10659/com.myApp E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)
抱歉很多日志

0 个答案:

没有答案