Activity of Android 4 components

Source: Internet
Author: User
1. Activities
Quickview

Activity is a component that provides users with an interactive interface. This interface is usually full screen, but it can also be a small window floating above other windows.

An android application is usually composed of multiple loosely coupled activities. Generally, there is a "Main" activity, which is displayed when the user starts the program for the first time.
Now in front of the user. The program then starts other activities based on the user's operations. When a new activity is started, the previous activity "stopped"
(But it does not have to be destroyed). The system saves it in "Back stack", and the newly started activity is placed in "back
Stack, and display it at the front of the screen. After the user completes the interaction with the activity at the beginning of the stack, the activity at the beginning of the stack is removed from the stack by clicking the back key.
Pop and destroy the previous activity resumes.

2. Activities lifestyle

Activity Status:

ResumedThe activity is at the front of the screen and obtains the user's focus.PausedThis activity is partially visible, but the user focus is on another activity floating above this activity window.StoppedThis activity is invisible, and of course there is no user focus.
Note: When the program is in the paused and stopped States, if the system memory is low, the system will kill the process to save memory. Callback Function of the activity (the function starting with "on" in the activity ):

Oncreate ()
Onrestar ()
Onstart ()
Onresume ()
Onpause ()
Onstop ()
Ondestory ()
Visible:

Onresume () and onpause () are a pair. They are called when the activity gets the user focus.
Onrestart (), onstart (), and onstop () belong to a ring, which is called based on whether the activity is visible or not.
When the program is in the paused and stopped status (that is, after the callback function onstop () or onpause () is called), if the system memory is low, the system will destroy this activity to save memory.

Table 1.A summary of the activity lifecycle's
Callback methods.

Method Description Can I be killed after being called? Next
Oncreate () It is called when an activity is created for the first time or when its memory is captured and then used by users. You can pass a bundle parameter to this method, which contains the previous status of the activity. No Onstart ()
Onrestart () It is called when the previous status is stopped and the current status is visible. No Onstart ()
Onstart ()

Called when the activity is visible.

Why is the next called function onstop ()??

No Onresume ()
Or
Onstop ()
Onresume ()

This API is called when an activity wants to obtain the user focus.

No Onpause ()
Onpause () It is called when the system needs to resuming another activity (that is, when it loses focus ).
It is best to save some variable data in this method.
Yes Onresume ()
Or
Onstop ()
Onstop () Called when activity becomes invisible. Yes Onrestart ()
Or
Ondestroy ()
Ondestroy () Called when the activity changes to destoried.
When the finish () method is called or the system temporarily destroys the instance of this activity to save memory space, this callback method is called.
You can use isfinishing () to differentiate the two cases.
Yes Nothing

Related Article

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.