简体   繁体   English

Android:onRetainNonConfigurationInstance()已弃用?

[英]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.

相关问题 屏幕旋转的AsyncTask - onRetainNonConfigurationInstance已弃用 - AsyncTask with screen rotation - onRetainNonConfigurationInstance deprecated Android-将数据库与onRetainNonConfigurationInstance一起使用 - Android - using database with onRetainNonConfigurationInstance Android-一种触发onRetainNonConfigurationInstance的方法? - Android - A way to trigger onRetainNonConfigurationInstance? 如何在Android的onRetainNonConfigurationInstance()中保存大量对象 - How to save lot of object in onRetainNonConfigurationInstance() in android Android:屏幕方向更改时未调用onRetainNonConfigurationInstance - Android : onRetainNonConfigurationInstance is not called on Screen orientation change Android:onRetainNonConfigurationInstance()和方向随着不同的布局而改变 - Android: onRetainNonConfigurationInstance() and orientation changes with different layouts 维护Android Activity的数据:onPause,onSaveInstanceState,onRetainNonConfigurationInstance - Maintaining Android Activity's data: onPause, onSaveInstanceState, onRetainNonConfigurationInstance 从onRetainNonConfigurationInstance()获取值时出现空指针异常-Android - Null pointer exception on getting value from onRetainNonConfigurationInstance() - Android Android:我可以通过 onRetainNonConfigurationInstance 保存一个 Drawable 或 Bitmap - Android: can I save a Drawable or Bitmap via onRetainNonConfigurationInstance android:onRetainNonConfigurationInstance,以及如何更改两次APK更新之间保存的内容? - android: onRetainNonConfigurationInstance and how to make changes to what’s saved between apk updates?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM