简体   繁体   中英

What is 'savedInstanceState'?

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

When an activity is re-initialized ,then the savedInstance contains the most recent data , specially contains data of the activity's previous initialization part.

Actually, when an activity is killed it saved its states so that when user back to this activity , it can restore its states

Basically bundle is a type of data structure which stores the data which was used previously in the activity..When there is some disturbance by the system or suppose some called u and u picked up phone then the data u had in ur app kept stored in bundle and you can access the same data..

And if we talk about savedinstancestate then it is very easy to know that basically savedinstancestate is an object/reference what ever doesn't matter but it is the way by which data will be kept stored...As u must know that class is just a prototype or blueprint (you may say) savedinstancestate is an object or reference.. Bundle is a class I think u know that..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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