android activity相关杂谈

看Activity启动流程中,记一下关于Launcher、SystemServer、Application的一些笔记。

Launcher

Launcher在onCreate时会创建LauncherModel并调用startLoader,创建LoaderTask。调用 loadWorkspace、bindWorkspace等。loadWorkspace会查询获取widget、shortcut、folder等一系列ItemInfo。对于ShortcutInfo,解析出包含intent,user等信息。这些ItemInfo将通过bindWorkspace传递给Launcher.bindItems,对于ShortcutInfo将创建BubbleTextView,并setTag将ShortcutInfo注入。于是乎,Launcher的onclick可以将view中的tag取出,若tag是ShortcutInfo类型,自然而然可以拿到用于启动activity的intent,和相关的user信息。

SystemServer

Activity启动流程中,LauncherAppsService.startActivityAsUser()使用了自己的Context:

public void startActivityAsUser(String callingPackage,
        ComponentName component, Rect sourceBounds,
        Bundle opts, UserHandle user) throws RemoteException {
   
    ...
        for (int i = 0; i < size; ++i) {
   
            ActivityInfo activityInfo = apps.get(i).activityInfo;
            if (activityInfo.packageName.equals(component.getPackageName()) &&
                    activityInfo.name.equals(component.getClassName())) {
   
                // Found an activity with category launcher that matches
                // this component so ok to launch.
                launchIntent.setComponent(component);
            	// 这里的context是SystemServer创建ContextImpl
                mContext.startActivityAsUser(launchIntent, opts, user);
                return;
            }
        }
...
}

那么context是从哪来的呢?我们知道LauncherAppsService是由SystemServer启动的:

// SystemServer
private void startOtherServices() {
   
...
	mSystemServiceManager.startService(LauncherAppsService.class);
...
}

// SystemManagerService
public SystemService startService(String className) {
   
    final Class<SystemService> serviceClass;
    try {
   
        serviceClass = (Class<SystemService>)Class.forName(className);
    } catch (ClassNotFoundException ex) {
   
        ...
    }
    return startService(serviceClass);
}
public <T 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值