android里每个服务启动时context
来源:互联网 发布:如何提升淘宝买家等级 编辑:程序博客网 时间:2024/05/16 06:04
1.android里每个服务启动时context到底从哪里来的呢????以mountservice的context为例在SystemServer.java的run函数中有如下代码 context = ActivityManagerService.main(factoryTest);......if...
1.android里每个服务启动时context到底从哪里来的呢????以mountservice的context为例
在SystemServer.java的run函数中有如下代码
context = ActivityManagerService.main(factoryTest);
......
if (!"0".equals(SystemProperties.get("system_init.startmountservice"))) {
try {
/*
* NotificationManagerService is dependant on MountService,
* (for media / usb notifications) so we must start MountService first.
*/
Slog.i(TAG, "Mount Service");
mountService = new MountService(context);
ServiceManager.addService("mount", mountService);
} catch (Throwable e) {
reportWtf("starting Mount Service", e);
}
}
由此可知,由systemserver启动的服务的context都来自ActivityManagerService
ActivityManagerService.java
public static final Context main(int factoryTest) {
......
ActivityThread at = ActivityThread.systemMain();
......
Context context = at.getSystemContext();
......
return context;
}
由上可知,该context是由ActivityThread 创建的
ActivityThread .java
public ContextImpl getSystemContext() {
synchronized (this) {
if (mSystemContext == null) {
ContextImpl context =
ContextImpl.createSystemContext(this);
LoadedApk info = new LoadedApk(this, "android", context, null,
CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO);
context.init(info, null, this);
context.getResources().updateConfiguration(
getConfiguration(), getDisplayMetricsLocked(
Display.DEFAULT_DISPLAY,
CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO));
mSystemContext = context;
//Slog.i(TAG, "Created system resources " + context.getResources()
// + ": " + context.getResources().getConfiguration());
}
}
return mSystemContext;
}
在ContextImpl .java中
static ContextImpl createSystemContext(ActivityThread mainThread) {
final ContextImpl context = new ContextImpl();
context.init(Resources.getSystem(), mainThread, Process.myUserHandle());
return context;
}
由此可知所有systemserver启动的服务的context对象实际为一个ContextImpl对象
即ServerThread::run<-ActivityManagerService.main<-ActivityThread::getSystemContext<-ContextImpl.createSystemContext
2.对于一个apk中的context一般直接指向这个activity本身,因为activity本身即继承自context
- android里每个服务启动时context
- android开机启动服务并在服务里启动activity
- Android里的Context
- android Context启动activity
- Android里Context的使用
- Android里Context的使用
- 谈谈Android里的Context的使用!!!
- 谈谈Android里的Context的使用!!!
- 谈谈Android里的Context的使用!!!
- 谈谈Android里的Context的使用!!!
- android里context从哪里来的????
- 谈谈Android里的Context的使用!
- Android里的Context的使用
- 谈谈Android里的Context的使用!!!
- android中的activity里获得context方法
- 谈谈Android里的Context的使用!!!
- 浅谈Android里的Context的使用
- android中的activity里获得context方法
- linux PATH环境变量缓存
- 计算机科学中最重要的32个算法(转)
- LAMP网站架构方案分析
- 练习1.20
- ios两个子视图同一时间进入和离开动画
- android里每个服务启动时context
- 在WINDOWS中设置计划任务执行PHP文件
- 人口和生育信息统计分析BI系统简介
- SPI协议及其工作原理浅析
- mysql-cluster-gpl-7.1.17 安装配置脚本
- 查看Windows 7的历史开机/关机时间
- 【hive】pentaho无法查询hive
- Apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for
- 神十与天宫一号返回的xml数据及读取方法