影子论坛

搜索
夜间模式◐

Android AMS--Activity相关数据类
[工作效率] · summer · 发布于 · 2020-06-28 · 374 次点击 · 复制地址

倔强青铜Ⅲ   summer  · 2020-06-28 20:21:27 · 显示全部楼层 · 阅读
AMS主要是负责四大组件的启动,进程调度以及在AMS中还会启动部分系统服务,主要是其他服务:startOtherServices
1:AMS的数据结构
6471821-90cf05fee27c913a.png
2:ActivityStackSuperVisor

ActivityStackSuperVisor是在ActivityManagerService初始化的时候创建的,ActivityStackSuperVisor主要是用来管理ActivityStack的,其内部管理了三个ActivityStack:mHomeStack,mFocusedStack,mLastFocusedStack,其中mHomeStack主要是用来管理LauncherActivity相关的Stack,mFocusedStack是指当前的焦点栈,mLastFocusedStack是上一次处于前台的栈,并且还有一个很重要的成员mactivityDisplays,在Android中一块显示屏幕对应一个ActivityDisplay,可以通过ActivityDisplay来管理某一显示屏上的Activity
3:ActivityDiplay

ActivityDisplay可以理解成一块屏幕,不同的屏幕通过displayId来区分,其管理者一组ActivityStack,当然也管理着特殊的栈
private ActivityStack mHomeStack = null;
private ActivityStack mRecentsStack = null;
private ActivityStack mPinnedStack = null;
private ActivityStack mSplitScreenPrimaryStack = null;
4:ActivityStack

ActivityStack才是我们通常说的Activity栈,其维护着一组TaskRecord和当前处理running状态的ActivityRecord,当然其也维护这几个比较特殊的Activity
   /**
     * The back history of all previous (and possibly still
     * running) activities.  It contains #TaskRecord objects.
     */
    private final ArrayList<TaskRecord> mTaskHistory = new ArrayList<>();
    /**
     * List of running activities, sorted by recent usage.
     * The first entry in the list is the least recently used.
     * It contains HistoryRecord objects.
     */
    final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<>
   /**
     * 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.
     */
    ActivityRecord mPausingActivity = null;
    /**
     * 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 sleeping,
     * when we normally hold the top activity paused.
     */
    ActivityRecord mLastPausedActivity = null;
    /**
     * Activities that specify No History must be removed once the user navigates away from them.
     * If the device goes to sleep with such an activity in the paused state then we save it here
     * and finish it later if another activity replaces it on wakeup.
     */
    ActivityRecord mLastNoHistoryActivity = null;
    /**
     * Current activity that is resumed, or null if there is none.
     */
    ActivityRecord mResumedActivity = null;

ActivityStack对应WindowManagerService的数据结构是TaskStack
5:TaskRecord

TaskRecord是用来管理一组相同taskId的ActivityRecord,其内部有一个很重要的数组:ArrayList<ActivityRecord> mActivities
final int taskId;       // Unique identifier for this task.
String affinity;
/** List of all activities in the task arranged in history order */
final ArrayList<ActivityRecord> mActivities;
/** Current stack. Setter must always be used to update the value. */
private ActivityStack mStack;
6:ActivityRecord

ActivityRecord是Activity在AMS中的描述,代表一个真正的Activity,与应用进程中的Activity是一一对应的,应用程序,AMS,WMS可以通过appToken关联起来,appToken是在ActivityRecord的构造方法中初始化的
ActivityRecord(ActivityManagerService _service, ProcessRecord _caller, int _launchedFromPid,
            int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
            ActivityInfo aInfo, Configuration _configuration,
            ActivityRecord _resultTo, String _resultWho, int _reqCode,
            boolean _componentSpecified, boolean _rootVoiceInteraction,
            ActivityStackSupervisor supervisor, ActivityOptions options,
            ActivityRecord sourceRecord) {
        service = _service;
        appToken = new Token(this, _intent);

ActivityRecord中成员变量
private TaskRecord task;        // the task this is in.
final IApplicationToken.Stub appToken; // window manager token
AppWindowContainerController mWindowContainerController;
final ActivityInfo info; // all about me

通过task可以找到其对应的task,appToken是其的标识,mWindowContainerController是和WMS的AppWindowToken关联的,info存储的是Activity的所有信息。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表