Android Interview summary on activity life cycle

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.