简体   繁体   中英

Android: onRetainNonConfigurationInstance() deprecated?

Inside my Activity I am instantiating an object which is responsible to query, process and store the data needed by the fragments. I was about to use onRetainNonConfigurationInstance() in order to retain the object after configuration changes, but I just realized the method has been deprecated.

I can see that the new recommended way is to use Fragment's setRetainInstance() , but it doesn't look like it's what I need, because my object doesn't deal with just 1 fragment.

Do you have any suggestions?

because my object doesn't deal with just 1 fragment

No, but your fragment can deal with whatever the object is.

onRetainNonConfigurationInstance() requires you to package everything into one object. Consider the retained fragment strategy to be requiring that this "one object" be a fragment, on which you call setRetainInstance() . Anything you could do with onRetainNonConfigurationInstance() should be doable with a retained fragment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM