[英]Android: onRetainNonConfigurationInstance() deprecated?
Inside my Activity I am instantiating an object which is responsible to query, process and store the data needed by the fragments. 在我的Activity里面我实例化一个对象,它负责查询,处理和存储片段所需的数据。 I was about to use
onRetainNonConfigurationInstance()
in order to retain the object after configuration changes, but I just realized the method has been deprecated. 我准备使用
onRetainNonConfigurationInstance()
以便在配置更改后保留对象,但我刚刚意识到该方法已被弃用。
I can see that the new recommended way is to use Fragment's setRetainInstance()
, but it doesn't look like it's what I need, because my object doesn't deal with just 1 fragment. 我可以看到新推荐的方法是使用Fragment的
setRetainInstance()
,但它看起来不像我需要的,因为我的对象不处理只有1个片段。
Do you have any suggestions? 你有什么建议吗?
because my object doesn't deal with just 1 fragment
因为我的对象只处理1个片段
No, but your fragment can deal with whatever the object is. 不,但你的片段可以处理任何对象。
onRetainNonConfigurationInstance()
requires you to package everything into one object. onRetainNonConfigurationInstance()
要求您将所有内容打包到一个对象中。 Consider the retained fragment strategy to be requiring that this "one object" be a fragment, on which you call setRetainInstance()
. 考虑保留的片段策略要求这个“一个对象”是一个片段,在其上调用
setRetainInstance()
。 Anything you could do with onRetainNonConfigurationInstance()
should be doable with a retained fragment. 你可以用
onRetainNonConfigurationInstance()
做的任何事都应该对保留的片段onRetainNonConfigurationInstance()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.