Save object while orientation change

后端 未结 4 1670
栀梦
栀梦 2021-02-02 07:20

How to save Object while orientation change, since onRetainNonConfigurationInstance and getLastNonConfigurationInstance are deprecated. And which cannot me used with compa

4条回答
  •  渐次进展
    2021-02-02 08:02

    When your Fragment is paused it will call this method:

    @Override
    public void onSaveInstanceState(Bundle outState) {
        // Add variable to outState here
        super.onSaveInstanceState(outState);
    }
    

    The variable outState will then be fed into the onCreate() method when the Fragment restarts.

    You can save any data that is a basic type or implements Parcelable interface

提交回复
热议问题