Skip to content Skip to sidebar Skip to footer

Fatal Exception: Java.lang.IllegalStateException No Activity

The Stacktrace I got in crashlytics fabric is as follows, Fatal Exception: java.lang.IllegalStateException: No activity at android.app.FragmentManagerImpl.moveToState(FragmentMa

Solution 1:

You are using wrong FragmentManager to nest the fragments. You should use fragmentManager instance returned by

getChildFragmentManager();  

instead of using

getSupportFragmentManager();

You can get more information about nested fragments here : https://developer.android.com/about/versions/android-4.2.html#NestedFragments

You can embed fragments inside fragments. This is useful for a variety of situations in which you want to place dynamic and re-usable UI components into a UI component that is itself dynamic and re-usable. You can insert fragments into each fragment page.

To nest a fragment, simply call getChildFragmentManager() on the Fragment in which you want to add a fragment. This returns a FragmentManager that you can use like you normally do from the top-level activity to create fragment transactions. For example, here’s some code that adds a fragment from within an existing Fragment class:

Fragment videoFragment = new VideoPlayerFragment();
FragmentTransaction transaction = 
      getChildFragmentManager().beginTransaction();
    transaction.add(R.id.video_fragment, videoFragment).commit();

From within a nested fragment, you can get a reference to the parent fragment by calling getParentFragment().


Post a Comment for "Fatal Exception: Java.lang.IllegalStateException No Activity"