java - what does super.onSaveInstanceState() do inside an overridden onSaveInstanceState() -
i new android development. using overriden version of onsaveinstancestate()
save own app data. noticed did not call super.onsaveinstancestate(savedinstancestate)
inside function , code worked fine.
@override public void onsaveinstancestate(bundle savedinstancestate) { // todo: // save state information collection of key-value pairs // 4 lines of code, 1 every count variable savedinstancestate.putint(create_key, mcreate); savedinstancestate.putint(resume_key, mresume); savedinstancestate.putint(restart_key, mrestart); savedinstancestate.putint(start_key, mstart); }
i wondering if super.onsaveinstancestate(savedinstancestate)
called implicitly ?
also, purpose of calling super.onsaveinstancestate(savedinstancestate)
inside overridden function.
when call super.onsaveinstancestate()
state of view
s saved.
if don't call super
method code still work...until...
...until application put in background because user presses home or runs application (via notification or whatever) , android kills application's process because has been in background awhile (or needs resources, or wants make life developer difficult).
then, when user returns application (by launching again, or selecting list of recent tasks), android happily create new process application , launch activity again , pass saved instance bundle (which doesn't have saved state of view
s because forgot call super
) , activity won't shown user in same state last left it. shown user initialized (default, empty, starting) state.
this why need call super.onsaveinstancestate()
, super.onrestoreinstancestate()
when override these methods.
Comments
Post a Comment