首先可以看看onResume的调用栈是哪里调用过来的
更多内容qqun:422901085 https://ke.qq.com/course/5992266#term_id=106217431
onResume:139, BaseQuickstepLauncher (com.android.launcher3)
callActivityOnResume:1531, Instrumentation (android.app)
performResume:8422, Activity (android.app)
performResumeActivity:4793, ActivityThread (android.app)
handleResumeActivity:4836, ActivityThread (android.app)
execute:54, ResumeActivityItem (android.app.servertransaction)
execute:45, ActivityTransactionItem (android.app.servertransaction)
executeLifecycleState:176, TransactionExecutor (android.app.servertransaction)
execute:97, TransactionExecutor (android.app.servertransaction)
handleMessage:2308, ActivityThread$H (android.app)
dispatchMessage:106, Handler (android.os)
loopOnce:201, Looper (android.os)
loop:288, Looper (android.os)
main:7898, ActivityThread (android.app)
invoke:-1, Method (java.lang.reflect)
run:548, RuntimeInit$MethodAndArgsCaller (com.android.internal.os)
main:936, ZygoteInit (com.android.internal.os)
明显可以看出是靠handler中对EXECUTE_TRANSACTION的消息进行处理execute会最后执行到Activity的onResume
case EXECUTE_TRANSACTION:
final ClientTransaction transaction = (ClientTransaction) msg.obj;
mTransactionExecutor.execute(transaction);
那么EXECUTE_TRANSACTION消息谁发送的?
其实是如下ClientTransactionHandler代码发送的:
public abstract class ClientTransactionHandler {
// Schedule phase related logic and handlers.
/** Prepare and schedule transaction for execution. */
void scheduleTransaction(ClientTransaction transaction) {
transaction.preExecute(this);
sendMessage(ActivityThread.H.EXECUTE_TRANSACTION, transaction);
}
再看看ActivityThread的结构:
public final class ActivityThread extends ClientTransactionHandler
implements ActivityThreadInternal {
那么又是谁调用过来的?那肯定是systemserver的跨进程调用的
scheduleTransaction:51, ClientTransactionHandler (android.app)
scheduleTransaction:1848, ActivityThread$ApplicationThread (android.app)
onTransact:1078, IApplicationThread$Stub (android.app)
execTransactInternal:1285, Binder (android.os)
execTransact:1244, Binder (android.os)
其中void scheduleTransaction(ClientTransaction transaction)参数ClientTransaction就是systemserver传递的对象,该对象的成员主要又2个:
/** A list of individual callbacks to a client. */
@UnsupportedAppUsage
private List<ClientTransactionItem> mActivityCallbacks;
/**
* Final lifecycle state in which the client activity should be after the transaction is
* executed.
*/
private ActivityLifecycleItem mLifecycleStateRequest;
mActivityCallbacks这里代表是一类独立的callback Item比如:
LaunchActivityItem它就包含要执行任务较多
mLifecycleStateRequest这里就是单独一个生命周期
如:ResumeActivityItem
它一个transation 执行在mActivityCallbacks后