如何保存很多对象在onRetainNonConfigurationInstance()在android系统 [英] How to save lot of object in onRetainNonConfigurationInstance() in android
问题描述
如何保存大量的对象在 onRetainNonConfigurationInstance()
像与价值和web视图与价值TextView的机器人,然后返回对象?
大家能否提供一个例子?
感谢
如何像价值和web视图与价值的TextView的android节省大量的对象在onRetainNonConfigurationInstance()。
块引用>您的例子是无效的。从来没有过活动实例间自己的小部件,因为你将创建内存泄漏。
有关
的WebView
,使用碎片和呼叫setRetainInstance(真)
的东西>的WebView -hosting片段。那么Android将处理所有的细节,以保持该的WebView
在活着的片段并将其连接到配置更改后创建的活动。有关,你有一个以上的对象从
onRetainNonConfigurationInstance返回的情况下()
,他们将不会引入内存泄漏,使用静态内部类,或的java.util
集合类,或者说为所有这些对象的容器,从onRetainNonConfigurationInstance返回容器()
。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
解决方案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 callsetRetainInstance(true)
on theWebView
-hosting fragment. Android will then handle all of the details to keep thatWebView
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 ajava.util
collection class, or something as the container for all those objects, and return the container fromonRetainNonConfigurationInstance()
.这篇关于如何保存很多对象在onRetainNonConfigurationInstance()在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!