How do I save a lot of objects in onRetainNonConfigurationInstance() in android like textview with value and webview with value, and then return the object?
Can anybody provide an example?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your example is invalid. Never pass widgets between activity instances yourself, as you will create memory leaks.
For stuff like
WebView, use fragments, and callsetRetainInstance(true)on theWebView-hosting fragment. Android will then handle all of the details to keep thatWebViewin its fragment alive and attach it to the activity created after a configuration change.For cases where you have more than one object to return from
onRetainNonConfigurationInstance(), and they will not introduce memory leaks, use a static inner class, or ajava.utilcollection class, or something as the container for all those objects, and return the container fromonRetainNonConfigurationInstance().