Save object while orientation change

后端 未结 4 1599
栀梦
栀梦 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 07:59

    There are two alternatives:

    1. Use a Loader. The FragmentActivity will take care of saving/restoring its state when re-creating.
    2. Use a fragment without a view and call setRetainInstance(true) on it. There is an example of this in the compatibility library's source, FragmentRetainInstanceSupport or some such.

提交回复
热议问题