The interview is often asked:
Q: Can you tell me the life cycle of the activity?
The activity life cycle is as follows:
Oncreat
OnStart
Onresume
OnPause
OnStop
Ondestory
Plus a onrestart.
As shown, the functions that are called when an activity is first started are
Oncreat
OnStart
Onresume method
Activty will run normally at this time
。
When it appears, the screen pops up with a dialog covering the activity, but this is what the activity also shows as part of the
OnPause is called, and the Onresume method is called when the activity returns to the foreground when dialog dismiss.
In another case, a activtiy jumps to another B activity, and the first a activity is completely overwritten when it is called
OnPause OnStop method, when the activity from B is returned, if at this point a activity is not destroyed (normally not destroyed),
The Onrestart OnStart Onresume method is called separately. The activity then goes into a normal state of operation.
This is roughly how the activity lifecycle call method is often answered during an interview.
Add a oncreat (Bundle savedinstancestate) below
When will the savedinstancestate be used?
For example, when the user enters "beauty" in the search box, but this is the user cleans up the memory to kill the process, we want the user to enter this activity interface to save the content of this search box how to do it?
This method can be called at this time
@Override
protected void Onsaveinstancestate (Bundle savedinstancestate)
{
Super.onsaveinstancestate (savedinstancestate);
Savedinstancestate.putstring ("Keytext", Searchedittext.gettext (). toString ());
}
Execute the following statement in the Oncreat method
if (savedinstancestate! = null)
{
Keytext = savedinstancestate.getstring ("Keytext");
Searchedittext.setstring (Keytext);
}
Can.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Interview summary on activity life cycle