The Android activity principle and its sub-class description

Source: Internet
Author: User

Brief introduction

Activity is an Android application component that implements a user interaction window that allows us to implement a layout fill screen or to implement a hover window. An app is composed of a number of actvitiy that distinguish between primary and secondary relationships with Intent-filter.
The following is a brief introduction to activity and its subclasses and other interfaces.

Details1. Activity


2, Listactivity



3, Activitygroup



4, Tabactivity



5, Preferenceactivity



6, Fragmentactivity


7, Listfragment



8, Nativeactivity



9, Expandablelistactivity



10, Launcheractivity



11, Aliasactivity


12, Preferencefragment

13, Activitycompat


14, Activityunittestcase


Activity management currently involves the activity management of the class two: 1, Localactivitymanager 2, Activitymanager. What have they done separately?





Life cycle



Here are three more critical lifecycles.

From the initial call to OnCreate (Bundle) to the final call OnDestroy () is called the full life cycle. The activity will set all the "global" states in OnCreate () and release all held resources in OnDestroy (). For example, if it has a background thread that downloads data from the network, he might create the thread in OnCreate () and stop the thread in OnDestroy ().

Starting with the activity call OnStart (), it is called the visible life cycle until the corresponding OnStop () is called. During this time, the user can see the activity on the screen, although not necessarily in the foreground or in the user interaction. Between the two methods you can maintain the resources that the activity requires when the user is displayed. For example, you can register a intentreceiver in OnStart () to monitor changes in the environment that can affect your UI, and you can unregister the Intentreceiver in OnStop () When your UI does not continue to appear in front of the user. The OnStart () and OnStop () methods can be called multiple times throughout the life cycle whenever the activity is displayed or hidden in front of the user.

Starting with the activity Call Onresume (), it is called the foreground life cycle until the corresponding OnPause () is called, and this time the activity is in front of all other activity and interacts with the user. An activity can often be converted between resumed and paused states-for example, when the phone enters hibernation, when the results of the activity are returned, and when the new intent arrives-so the code in these two methods should be very brief.

The activity method below defines the full life cycle of the activity. They are all hook methods, and you can overload these methods so that the activity performs the actions you expect when the state changes. All activity should implement its own OnCreate (Bundle) method to initialize the settings, and most should implement the OnPause () method to commit the data modification and prepare to terminate the interaction with the user. Although we plan to add more tools to the system to manage the application, most of the activity still needs to implement Onfreeze () and perform the corresponding state recovery in the OnCreate (Bundle). Other methods can be implemented when needed, and it is important to note that the corresponding methods in the parent class must be called when implementing these methods.

The Android activity principle and its sub-class description

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.