Should I implement onRetainNonConfigurationInstance?

I just read about saving the state of my Android app and stumbled upon onRetainNonConfigurationInstance. But while reading the documentation , I noticed this suggestion:

This function is called pure optimization, and you should not rely on its call.

So I'm wondering: when does it really make sense to use this method. If I cannot rely on its call, I need one more mechanism for transferring state anyway (which in my case will be some kind of serialization). Therefore, if I do not have any performance achievements, is there any reason why I should go onRetainNonConfigurationInstance?

If it were guaranteed to be triggered, I would love to use it, but if it is not, it looks useless.

Am I missing something? When do you use this method? How would you support a network connection or something like that?

Thanks!

+6
android state
source share
1 answer

What documentation means is when the activity will not be recreated immediately, in which case onRetainNonConfigurationInstance () will not be called. You cannot use this method to save data. It is used only to transfer objects that must be created when a configuration is changed.

+12
source share

All Articles