你能解释一下 onCreate 和 Bundles 吗?
我一直在查找它,但我似乎无法将自己包裹在 onCreate 和 Bundles 中。我知道 onCreate 在程序启动时被调用,但它是如何传递 Bundles 以及它们如何相关的。任何人都可以尝试用简单的英语来表达它,因为我似乎找不到它的详细描述。
谢谢
I have been looking it up and I just cant seem to wrap myself around the onCreate and Bundles. I understand that the onCreate is called when the program starts but its how the Bundles get passed around and how they are pertinent. Can anyone try to put this into plain english because I cant seem to find it well described.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
onCreate
方法中的Bundle
应保留 Activity 被终止之前的状态。简单的示例,当您更改设备的方向时,您的活动将被重新创建。
想象一下,用户正在填写一份长表单,并且他/她不小心改变了方向。当应用程序重新启动时,所有输入的数据都将丢失,除非您保留该信息。一种可能性是使用 Bundle。
如果您想了解如何使用它,我建议您阅读 这个问题。
The
Bundle
in theonCreate
method should hold the state of you activity before it was killed.Simple example, when you change the orientation of your device your activity is recreated.
Imagine the user is filling a long form and he/she accidentally changes the orientation. When the app gets restarted all data entered will be lost unless you persist that information. One possibility is using a Bundle.
If you want to know how to use it, I would recommend that you read this question.