Activity of Android four components

Source: Internet
Author: User

The role of 1.Activity

Activity is the interface between the user and the Android program. An activity is the equivalent of a window in which various controls can be placed to interact with the user. Windows are usually filled with screens, but can also be smaller than the screen and float on top of other windows. Functionality is similar to a controller in MVC design mode, but it is not a user interface in itself.

The 2.Activity life cycle consists of the following 7 methods

Created: OnCreate ()

Start: OnStart ()

Recovery: Onresume ()

Pause: OnPause ()

Stop: OnStop ()

Destroyed: OnDestroy ()

Restart: Onrestart ()

This is just literally the meaning of English, in the application the method is actually 22 correspondence:

OnCreate () and OnDestroy (): Can be understood as creating application windows and destroying Windows

OnStart () and OnStop (): Can be understood as visible and invisible to the program window

Onresume () and OnPause (): It can be understood that the program window gets focus (or edit) and loses focus

Onrestart (): After the activity has been onstop, but not OnDestroy, when the activity is started again call Onrestart (and no longer call OnCreate) method;

OnDestroy, the OnCreate method is called.

3.Activity Boot Order

Start order of the first activity: OnCreate (), OnStart (), Onresume ()

Start order of the second activity: the first activity OnPause () The second activity onCreate (), OnStart (), Onresume (), and OnStop ()

Return to the first activity boot order: The second Activity onPause (), the first activity Onrestart (), OnStart (), Onresume (), Second Activity onStop ()

OnDestroy ()

In addition, the activity in the OnPause, OnStop, OnDestroy state, the system can destroy the activity of the process, so we are processing the data to be saved,

It is best to onpause methods because the OnStop and OnDestroy methods are not necessarily called.

Activity of Android four components

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.