Activity与AMS跨进程通讯方式更新部分

首先可以看看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后

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值