Some summary of the activity of Android core components

Source: Internet
Author: User

Activity Life cycle Methods:

Activity is one of the core components of Android system, which is mainly used to deal with interface related business and to respond to user's related operation on interface. The related time-consuming operations performed at this interface (for example:

Child thread hibernation, never stable network access data, etc.) should in principle

Executes in a child thread to avoid anr:application not responding.

The entire process of creating an object from creation to destruction executes a specific declaration cycle method.

One, when the object is first started: Execute Oncreat () method-->onstart () method-->onresume () method;

Second, when the object is not visible: Execute OnPause () method-->onstop () method;

Third, when the object is re-visible: Execute Onrestart () method-->onstart () method-->onresume () method;

Iv. when the object is destroyed: Execute the OnPause () method-->onstop () method-->ondestory () method.

Note: The above method is called by the system, and the finish () method needs to be called manually when other objects need to be actively destroyed.

Status of activity:

The state of the object is broadly divided into four types, 1, operating state: placed in the foreground, visible and controllable.

2, stop state: Placed in the background, not visible and not controllable.

3, termination state: destroyed, that activity has been callback OnDestroy () method.

4, suspended state: activity is partially visible, but not controllable, usually caused by other non-activity occlusion.

Creation of activity:

After you create a class to inherit activity, register it first and create its layout. Second, rewrite the Oncreat () method in the newly created class.

Activation and destruction of activity:

When the new object needs to be activated, call the StartActivity (Intent) method and destroy the call to the finish () method.

activation mode of activity;

The system uses a task stack to record activity components that the application has activated, and when the back return key is used, the previous interface is displayed based on the records in the task stack.

Components are recorded in the task stack by means of a stack and a stack. While the startup mode of the component will affect its record in the task stack, the Android project manifest profile Androidmanifest.xml

Configure the Android:launchmode property within the <activity> node in the. The properties are divided into four types: 1, when the activity object is activated each time, a new object is created and the standard mode of the stack is set, and this mode is the default.

2. When activity is activated at the top of the stack, the new object's stack top unique mode singletop is not created. 3. When the activity is not changed in the task stack, the activation will create a new object and press the stack when it already exists.

, when you press the back key, activation will not create a new object, but rather a stack, at which point the other activity on top of it will be forced to reload. That is Singletask, the only mode within the stack. 4, alone occupies a task stack within the SingleInstance stack instance unique mode.



Some summary of the activity of Android core components

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.