Skip to content Skip to sidebar Skip to footer

How To Save Lot Of Object In Onretainnonconfigurationinstance() In Android

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

Solution 1:

How to save lot of object in onRetainNonConfigurationInstance() in android like textview with value and webview with value .

Your example is invalid. Never pass widgets between activity instances yourself, as you will create memory leaks.

For stuff like WebView, use fragments, and call setRetainInstance(true) on the WebView-hosting fragment. Android will then handle all of the details to keep that WebView in 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 a java.util collection class, or something as the container for all those objects, and return the container from onRetainNonConfigurationInstance().

Post a Comment for "How To Save Lot Of Object In Onretainnonconfigurationinstance() In Android"