AMS 代码走读: Activity Start Procedure


ActivityManagerService Part 2: Activity Start Procedure

We walk through the start process of an Activity. During the journey,  we will see important structure representing Activity, Process, Stack and Task. The detailed information regarding stack and task were described in Android developer website. I will only focus on the key method which is related to starting activity. Trivia logic will be skipped.

Phase 1: Create Data Structure For Target Activity

Let’s see the code flow below.

圖片1

According to above sequence chart, the first important method which is worthy to be discussed is “startActivityMayWait“. The main task of it is collecting the target activity information via package manager then maintain the information by ActivityInfo.java. ActivityInfo is then utilized in next phase.

圖片2

In continued phases, activity managed classes are adopted. Theses classes include ActivityRecord, TaskRecord and ActivityStack (see here for concept). The class dependency is as below figure.

圖片3

Let’s continue the code flow. Now, two major objects managing activity are created.

圖片5

A new created task was then put at the top of stack. Refer to following code snippet.

圖片6

Phase 2: Create Process

In phase 1, we collected information for Activity and created vessels (ActivityRecord and TaskRecord) for it. Next step is to try to “resume" the activity to show. Before resuming target activity, current activity who launched target activity should be put into ground. Yes, it should enter “paused" state. Let’s see how it works.

圖片7

resumeTopActivitiesLocked is the main entry point to phase 2. I summarize two major tasks in resumeTopActivitiesLocked method in below figure. We don’t discuss the activity pausing flow here. I left it to We focus on starting activity.

圖片8

While starting a new activity, system will try to find an existed process or just create a new one.

圖片10

Now, system creates a new process. The newly created process is only a vessel. It is not related to the target activity yet.

圖片11

Following code snippet indicates an important method of “bindApplication“. We skip it here. Focus on start activity flow.

圖片12

圖片13

Phase 3: Activity Ready to GO

In this phase, an Activity object is created and ready to GO.

圖片14

圖片15

Summary

It’s a very long journey to walk through the activity start process. I don’t plan to end here. I will discuss details of bindApplication and performLaunchActivity in next article.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值