Fragment Must Be a Public Static Class to Be Properly Recreated from Instance State

Fragment must be public static class to be properly recreated from instance state

Your top level file is not visible by Android Framework to be managed by the FragmentManager.

class OverviewFragment extends Fragment

You need to make your class public. Not package default, as you have it right now. Your Fragment should be defined next.

public class OverviewFragment extends Fragment

IllegalStateException: Fragment null must be a public static class to be properly recreated from instance state

  1. get rid of:

    @SuppressLint("ValidFragment")
    public MapRestaurant(MainActivity fmMain) {
    this.fmMain = fmMain;
    }

    public MainActivity getFmMain() {
    return fmMain;
    }

    public void setFmMain(MainActivity fmMain) {
    this.fmMain = fmMain;
    }

Android keeps that reference for you. Use getActivity() to retrieve the hosting Activity. Same thing applies to contexto = v.getContext();.


  1. Change

    getFmMain().getSupportFragmentManager()

with getFragmentManager(). If you did import Fragments from the support library, in a Fragment's subclass, getFragmentManager(), returns the support version of the FragmentManager. No need of magic

Fragment must be a public static class crash error after upgrade repo v9 in android studio

Is ArrayListFragment in the same java file as the CategoryActivity? If it true, static class means that an instance of ArrayListFragment can be created without creating an instance of CategoryActivity. So each class can have own instance of ArrayListFragment.



Related Topics



Leave a reply



Submit