简体   繁体   English

`Bundle savedInstanceState` 的范围是什么

[英]What is the scope of `Bundle savedInstanceState`

In android, we preserve the instance state of our activities by using onSaveInstanceState(Bundle outState) .在android中,我们通过使用onSaveInstanceState(Bundle outState)来保存我们活动的实例状态。

Now in order to properly implement this it is necessary to have a unique string key for all variables stored inside outState .现在,为了正确实现这一点,有必要为存储在outState所有变量设置一个唯一的字符串键

I am curious of how unique I need to make this string.我很好奇制作这个字符串需要多么独特。

1) Is the Bundle propagated via the Android OS to all active Activities - therefore all keys must be Application & activity namespaced ? 1) Bundle是否通过 Android 操作系统传播到所有活动活动 - 因此所有键都必须是应用程序和活动命名空间
(eg com.twitter.www.mobile.LOGIN_ACTIVITY.is_logged_in ) (例如com.twitter.www.mobile.LOGIN_ACTIVITY.is_logged_in

2) Is the Bundle only accessed by the Activity in which it was called- therefore all keys must only be Application namespaced ? 2) Bundle是否只能由调用它的 Activity 访问 - 因此所有键只能是Application 命名空间
(eg com.twitter.www.mobile.is_logged_in ) (例如com.twitter.www.mobile.is_logged_in

The bundle in a particular Fragment or Activity is unique only that Fragment or Activity .在一个特定的束FragmentActivity是独特仅FragmentActivity They are not propagated throughout the application.它们不会在整个应用程序中传播。 It's always good to be verbose/specific in your keys and variables to avoid confusion but you do not have to worry about accessing the wrong instance state bundle or key-value pair from a different activity or fragment.在您的键和变量中详细/特定以避免混淆总是好的,但您不必担心从不同的活动或片段访问错误的实例状态包或键值对。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM