0

I know there are lots of same question and I checked its solutions\ suggestions. However, they are not working for me. I am trying to add fragment and when I am calling fragmentTransaction.commit() it throws that exception, but that happens only with my 2nd fragment.

I send a notification to my application, when it is clicked, it opens my app which open main fragment, at that time getSupportFragmentManager().findFragmentById(R.id.rl_content_fragment); returns null for current fragment ( which should be correct ), problem is my 2nd fragment ( playerFragment) when I try to add it ( while debugging) I found out that getSupportFragmentManager() still returns null for current fragment and it throws the exception that the activity has been destroyed when I call fragmentTransaction.commit().

My questions

1-is why does the Activity gets destroyed or finish while the application is starting?

2-how can I fix that issue?

Any hint will be appreciated, thanks. EDIT this is the exception which I get, I know I should not change views unless I am on mainThread, but I do report on main thread, Sorry forgot to say we are using commitAllowingStateLoss() and this what i get

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)

and if i use commit() I get this exception

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)

sorry for much logs

M.Baraka
  • 725
  • 1
  • 10
  • 24

0 Answers0