什么的OnCreate(束savedInstanceState) [英] What's onCreate(Bundle savedInstanceState)

查看:169
本文介绍了什么的OnCreate(束savedInstanceState)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能帮助我了解的捆绑savedInstanceState 的onCreate(包savedInstanceState)我是新手在Android中。我试着去了解它developer.android.com。但我不能够理解。任何人都可以简化呢?

Can anyone help me to know about the Bundle savedInstanceState in onCreate(Bundle savedInstanceState) I am newbie in Android. I try to understand it from developer.android.com. But I am not able to understand. Can anyone simplify it?

推荐答案

如果您保存在一个包(通​​常是非持久性的,动态的数据的onSaveInstanceState ),它可以被传递回的onCreate 如果活动需要重新创建(如方向变化),这样你就不能失去这个先验信息。如果没有数据,, savedInstanceState 为空。

If you save the state of the application in a bundle (typically non-persistent, dynamic data in onSaveInstanceState), it can be passed back to onCreate if the activity needs to be recreated (e.g., orientation change) so that you don't lose this prior information. If no data was supplied, savedInstanceState is null.

...你   应该使用的onPause()方法写入任何永久数据(如   用户编辑)到存储。此外,该方法   的onSaveInstanceState(捆绑)将在活动前被称为   这样的背景状态,让您保存走任何动态   在您的活动到给定的包实例的状态,要晚   在的onCreate(束)接收如果活动需要被重新创建。   请参阅流程生命周期一节的详细信息如何   一个过程的生命周期依赖于它承载的活动。注意   以保存在的onPause(持久性数据),而不是认为是很重要的   的onSaveInstanceState(束),因为后者没有的部分   生命周期的回调,这样就不会被调用在任何情况下为   其文档中描述。

... you should use the onPause() method to write any persistent data (such as user edits) to storage. In addition, the method onSaveInstanceState(Bundle) is called before placing the activity in such a background state, allowing you to save away any dynamic instance state in your activity into the given Bundle, to be later received in onCreate(Bundle) if the activity needs to be re-created. See the Process Lifecycle section for more information on how the lifecycle of a process is tied to the activities it is hosting. Note that it is important to save persistent data in onPause() instead of onSaveInstanceState(Bundle) because the latter is not part of the lifecycle callbacks, so will not be called in every situation as described in its documentation.

这篇关于什么的OnCreate(束savedInstanceState)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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