ViewPage Fragment disappear when reload again

前端 未结 5 1318
执笔经年
执笔经年 2021-02-06 05:20

The following is layout

test.xml





        
5条回答
  •  我寻月下人不归
    2021-02-06 05:34

    In your Fragment class, in the onCreate() method, you have to call setRetainInstance(true) like this:

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);     
        setRetainInstance(true);
    }
    

    This tells the FragmentManager to keep your fragments on reloads. In addition, check your manifest file doesn't have any

    android:screenOrientation
    

    config changes where you are basically saying you will handle reloads due to config changes yourself.

提交回复
热议问题