如何保存很多对象在onRetainNonConfigurationInstance()在android系统 [英] How to save lot of object in onRetainNonConfigurationInstance() in android

查看:165
本文介绍了如何保存很多对象在onRetainNonConfigurationInstance()在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 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().

这篇关于如何保存很多对象在onRetainNonConfigurationInstance()在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆