ActivityStack introduction and activitystack Introduction

Source: Internet
Author: User

ActivityStack introduction and activitystack Introduction

Reprinted please indicate the source:

Http://blog.csdn.net/yujun411522/article/details/46659413
This article is from: [yujun411522 blog]




When ActivityManagerService is started, the ActivityStack class appears. What is the role of this class?

We know that Activity is responsible for display and interaction in Android. If there is such a startup sequence Activity1-> Activity2-> Activity3, Activity3 is displayed, when we press the return key, we return to Activity2 and press the return key again to return to activity1. This interaction logic is in line with our habits. This kind of data structure is stack, and stack is used to manage Activity in android. The system always displays the Activity at the top of the stack. Every time a new Activity is started, the Activity at the top of the stack is replaced by a new Activity, the system displays the new Activity. When the user returns the same result, the Activity at the top of the stack will go out of the stack, and the Activity at the bottom of the original stack will be at the top of the stack, and the system will display it. Until all the activities in the ActivityStack no longer exist, return to the Home interface.
Next, let's take a look at the important member variables and methods in AndroidStack. 1 ActivityStateAn Activity may be in the following status:
Enum ActivityState {INITIALIZING, // initializing resumed, // get focus PAUSING, // pause PAUSED, // STOPPING has been PAUSED, // STOPPED is being STOPPED, // The FINISHING has been stopped, // The DESTROYING is being completed, // The DESTROYED is being DESTROYED // The DESTROYED has been DESTROYED}
For more information about status changes, see the Activity lifecycle change diagram.



2 ArrayList <ActivityRecord>Stores a series of Activity sets with different functions. ActivityRecord is used here. This class is used to record the running information of each Activity, mainly including the following Arraylist
/*** The back history of all previous (and possibly still running) activities. it contains HistoryRecord objects. * // all returned activities final ArrayList <ActivityRecord> mHistory = new ArrayList <ActivityRecord> ();/*** List of running activities, sorted by recent usage. the first entry in the list is the least recently used. * It contains HistoryRecord objects. * // The running activities are sorted by LRU. The first is the final ArrayList <ActivityRecord> mLRUActivities = new ArrayList <ActivityRecord> (); /*** List of activities that are waiting for a new activity to become visible before completing whatever operation they are * supposed to do. * /// the final ArrayList <ActivityRecord> mWaitingVisibleActivities = new ArrayList <ActivityRecord> () of the Activity set waiting for a new Activity to become Visible (); /*** List of activities that are ready to be stopped, but waiting for the next activity to settle down before doing so. it contains * HistoryRecord objects. * // The Activity set final ArrayList <ActivityRecord> mStoppingActivities = new ArrayList <ActivityRecord> () is waiting for another Activity to Stop completely (); /*** List of activities that are in the process of going to sleep. * // The final ArrayList <ActivityRecord> mGoingToSleepActivities = new ArrayList <ActivityRecord> () of the Activity set in the sleep process (); /*** Animations that for the current transition have requested not to be considered for the transition animation. * // The final ArrayList <ActivityRecord> mNoAnimActivities = new ArrayList <ActivityRecord> ();/*** List of activities that are ready to be finished, but waiting for the previous activity to settle down before doing so. it contains * HistoryRecord objects. * /// wait for the last Activityfinished Activity set final ArrayList <ActivityRecord> mFinishingActivities = new ArrayList <ActivityRecord> ();


3. Special ActivityThere are also some activities that record special states, including:
/*** When we are in the process of pausing an activity, before starting the next one, this variable holds the activity that is currently being paused. * /// use this variable to save the Activity ActivityRecord mPausingActivity being paused before a new Activity is started; /*** This is the last activity that we put into the paused state. this is used to determine if we need to do an activity transition while sleepi Ng, * when we normally hold the top activity paused. * // The Last paused Activity ActivityRecord mLastPausedActivity = null;/*** Current activity that is resumed, or null if there is none. * // Activity ActivityRecord mResumedActivity in the resume status = null;/*** This is the last activity that has been started. it is only used to identify when multiple activities are started at once so that the user * ca N be warned they may not be in the activity they think they are. * // recently started Activity. ActivityRecord mLastStartedActivity = null;
These variables are used to record and manage the data structure of the Activity. There are many methods in ActivityStack.
These are all used to schedule the Activity, and subsequent calls to these methods will be involved in starting the Activity.

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.