I see IllegalStateException in Google-Play Console, which I can't reproduce.
Here is the stack trace:
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3349)
at android.app.ActivityThread.access$1100 (ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1794)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:158)
at android.app.ActivityThread.main (ActivityThread.java:7224)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)
Caused by: java.lang.IllegalStateException:
at android.support.v4.app.FragmentManagerImpl.getFragment (FragmentManager.java:668)
at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:999)
at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1252)
at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1234)
at android.support.v4.app.FragmentManagerImpl.dispatchCreate (FragmentManager.java:2041)
at android.support.v4.app.Fragment.performCreate (Fragment.java:1964)
at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1029)
at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1252)
at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1234)
at android.support.v4.app.FragmentManagerImpl.dispatchCreate (FragmentManager.java:2041)
at android.support.v4.app.Fragment.performCreate (Fragment.java:1964)
at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1029)
at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1252)
at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1234)
at android.support.v4.app.FragmentManagerImpl.dispatchCreate (FragmentManager.java:2041)
at android.support.v4.app.FragmentController.dispatchCreate (FragmentController.java:163)
at android.support.v4.app.FragmentActivity.onCreate (FragmentActivity.java:331)
at android.support.v7.app.AppCompatActivity.onCreate (AppCompatActivity.java:85)
at com.example.eliran.forum.RootActivity.onCreate (RootActivity.java:53)
at com.example.eliran.forum.MainActivity.onCreate (MainActivity.java:58)
at android.app.Activity.performCreate (Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3206)
I have activity with NavigationView which contains fragments.
I suspect that this exception happens when the user press on the back button and a function that contains the following code is called:
if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
getSupportFragmentManager().popBackStack();
}
Google-Play console doesn't display this, but this is the exception error:
throwException(new IllegalStateException("Fragment no longer exists for key "
+ key + ": index " + index));
You probably use setTargetFragment() somewhere in your code. Just avoid using it. Instead, communicate between the fragemnts via callback and listener like this: In fragmentDialog -
protected OnRemovedTopicListener callback = null;
public interface OnRemovedTopicListener {
public abstract void onTopicRemoved(int position);
}
public void setOnRemovedTopicListener(OnRemovedTopicListener l){
callback = l;
}
and using the callback - callback.onTopicRemoved(position);
In the parent fragment -
dialogFragment.setOnRemovedTopicListener(new ForumTopicDialogFragment.OnRemovedTopicListener() {
@Override
public void onTopicRemoved(int position) {
// you code here
}
});