I am new to Android Development but I have some knowledge of OOP concepts. I am trying to learn Android from Java perspective.
I understand that savedInstanceState inside onCreate() on line 9 is the declaration of Bundle class. On line 10 we are calling the onCreate() method from the super class.
Here is what I don't unterstand: On line 10 we pass savedInstanceState itself as a parameter to the onCreate() method. This doesn't make sense to me as I would expect to pass an object which is of the Bundle type, but instead of that we pass a reference not an object of type Bundle to the method.
The savedInstanceState is a reference to a Bundle object that is passed into the onCreate method of every Android Activity.
The onCreate() expects to be called with a Bundle as parameter so we pass savedInstanceState.
Activities have the ability, under special circumstances, to restore themselves to a previous state using the data stored in this bundle. If there is no available instance data, the savedInstanceState will be null.
For example, the savedInstanceState will always be null the first time an Activity is started, but may be non-null if an Activity is destroyed during rotation, because onCreate is called each time activity starts or restarts.
Hope it helps
这篇关于什么是“已保存实例状态"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
为什么在 Eclipse 的 SDK 中选择 Android API 而不是 Why would you choose Android API over Google APIs in the SDK on Eclipse?(为什么在 Eclipse 的 SDK 中选择 Android API 而不是 Google API?)
Couchbase 存储桶身份验证错误Couchbase Bucket authentication error(Couchbase 存储桶身份验证错误)
admob 6.2.1 空指针异常admob 6.2.1 nullpointer exception(admob 6.2.1 空指针异常)
如何在 IntelliJ IDEA 中设置 SDK?How to setup SDK in IntelliJ IDEA?(如何在 IntelliJ IDEA 中设置 SDK?)
eclipse 无法检测到我的手机进行试运行My phone cannot be detected in eclipse to test run(eclipse 无法检测到我的手机进行试运行)
android SDK 中缺少 platform-toolsaapt.exe 目录platform-toolsaapt.exe directory missing in android SDK(android SDK 中缺少 platform-toolsaapt.exe 目录)