Android Learning note--activity Startup and creation

Source: Internet
Author: User

Android Activity Learning note--activity Startup and creation

Recently learning about Android, it feels like just knowing the activity of several life cycle functions is basically meaningless;

So I want to learn more about how the activity is how it works, and what is inside is really called a huge;

Now it is only easy to understand the concept and process of its framework;

An activity concept

The core of Android is not application but activity, at least when we develop it;

Activity is a component that is used to interact with the user and to interact with the Android internal features.

All activity in the application needs to be registered in the Manifest.xml file;

So what is activity and what kind of component, how to display the interaction, how an activity instance is managed and run, and what the activity life cycle is all about.

II. activity framework and management structure

The core of activity management is Acitivitymanagerservice, which is an independent process;

Activethread is the main thread of the process in which each application is located, looping message processing;

The communication between Activethread and Acitivitymanagerservice belongs to interprocess communication, using binder mechanism;


Three Activity initiation Process

To start an application startactivity for example, take a look at the approximate flow of code execution:


It can be divided into 6 processes:

1 Use the proxy mode to boot into the activitymanagerservice execution;

2 Create Activityrecord to Mhistory records;

3 Create process through socket communication to zgote related classes;

4 Establish communication with Activitymanagerservice through Applicatonthread;

5 Activitymanagerservice notify Activethread to initiate activity creation;

6 Activitythread create activity to join in mactivities and start scheduling activity execution;

Please see:



Not all starting an activity is the process: all activity in an application has only one activitythread belonging to a process;

Activitystack not always need to create a stack to manage activities;

Here's a look at four important concepts in the adnroid system:

application: consists of multiple related loosely interacting activity with the user, usually packaged into an apk suffix file;

Activities: The main component of the application is the core of the application;

activitystack: The activity that opens in the application is saved in the history stack, according to the advanced post-out principle of the stack;

Start activity in the stack, return to the stack;

Task: A series of related activity combinations to complete the operation of an application, regardless of where the activity belongs

a application;

For example: Write message-call-file management, all belong to a task, but belong to two application;

Four activity initiation Process class structure analysis 1 Activityservice related classes

Use proxy mode: Activitymanagerproxy agent Activitymanagerservice;

and provides a public access interface: Iactivitymanager;


2 Activity Activation



3 Activitystack Management


Activitystack Create and store the activity instances created by the series and put them into the stack management mhistory;

4 Activitythread

Thismanages the execution of the main thread in anapplication process,

Schedulingand executing activities,broadcasts, and other operations on it as the Activitymanager requests.

is the main thread of the application, the message loop performer, which has many internal classes to complete the work;

Activitythread uses internal classes: Applicationthread communicates with Activitymanagerservice,

Activitythread state Change Delivery Control client activity state execution;

Mactivities Save the Activityrecord related instance references created by Activitystack;



With the help of some people on the net and their own combination of code analysis, summed up the above process framework aspects;

may not necessarily be accurate or the existence of loopholes, ask the talent guidance Thank you;

Android Learning note--activity Startup and creation

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: 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.