As far as I can see onRetainNonConfigurationInstance is a redundant callback. If my activity has really expensive initialization, I am better off using onSaveInstanceState. Saved instance covers more situations than non-configuration instance. Is there any guideline for using one API vs. the other? Thanks.
As far as I can see onRetainNonConfigurationInstance is a redundant callback.
No, it is not.
If my activity has really expensive initialization, I am better off using onSaveInstanceState.
onSaveInstanceState()
is not designed for "really expensive initialization". It is designed for "hey, the user made some changes to the information in the activity but has not saved it yet, let's not lose that data, m'kay?".
Is there any guideline for using one API vs. the other?
If it fits in a Bundle
and is not too big, use onSaveInstanceState()
. Everything that does not fit in a Bundle
(e.g., a socket) or is really big (e.g., a photo as a Bitmap
) should use onRetainNonConfigurationInstance()
, and your application should be in position to re-create those items if needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With