Stop fragment from being recreated after resume?

前端 未结 3 1798
无人及你
无人及你 2021-01-04 08:06

I am using several fragments to be dynamically added into activity. Everything works fine, when I press back-button, the fragments go

3条回答
  •  独厮守ぢ
    2021-01-04 08:27

    In the Activity's onCreateView set the savedInstanceState to null before calling the super method. You could also remove only the keys "android:viewHierarchyState" and "android:fragments" from the savedInstanceState bundle. Here is code for the simple solution, nulling the state:

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        savedInstanceState = null;
        super.onCreate(savedInstanceState);
    
        ...
    }
    

提交回复
热议问题