Android之getSystemService
getSystemService是Android很重要的一个API,它是Activity的一个方法,根据传入的NAME来取得对应的Object,然后转换成相应的服务对象。以下介绍系统相应的服务。
| 传入的Name | 返回的对象 | 说明 |
| WINDOW_SERVICE | WindowManager | 管理打开的窗口程序 |
| LAYOUT_INFLATER_SERVICE | LayoutInflater | 取得xml里定义的view |
| ACTIVITY_SERVICE | ActivityManager | 管理应用程序的系统状态 |
|
POWER_SERVICE |
PowerManger | 电源的服务 |
| ALARM_SERVICE | AlarmManager | 闹钟的服务 |
|
NOTIFICATION_SERVICE |
NotificationManager | 状态栏的服务 |
| KEYGUARD_SERVICE | KeyguardManager | 键盘锁的服务 |
| LOCATION_SERVICE | LocationManager | 位置的服务,如GPS |
| SEARCH_SERVICE | SearchManager | 搜索的服务 |
| VEBRATOR_SERVICE | Vebrator | 手机震动的服务 |
| CONNECTIVITY_SERVICE | Connectivity | 网络连接的服务 |
| WIFI_SERVICE | WifiManager | Wi-Fi服务 |
| TELEPHONY_SERVICE | TeleponyManager | 电话服务 |
getSystemService()方法是如何实现的?
|
在研究Android Application Framwork层的源代码遇到一个问题
就是Activity里面的getSystemService()方法是怎么实现的? 我觉得会不会是系统自动调用native实现这个抽象类Context? |
你好 在 framework 层文件 ContextImpl.java 文件里面
根据service 的类型 调用相应的 manager层
public Object getSystemService(String name) {
if (WINDOW_SERVICE.equals(name)) {
return WindowManagerImpl.getDefault();
} else if (LAYOUT_INFLATER_SERVICE.equals(name)) {
synchronized (mSync) {
LayoutInflater inflater = mLayoutInflater;
if (inflater != null) {
return inflater;
}
mLayoutInflater = inflater =
PolicyManager.makeNewLayoutInflater(getOuterContext());
return inflater;
}
} else if (ACTIVITY_SERVICE.equals(name)) {
return getActivityManager();
} else if (INPUT_METHOD_SERVICE.equals(name)) {
return InputMethodManager.getInstance(this);
} else if (ALARM_SERVICE.equals(name)) {
return getAlarmManager();
} else if (ACCOUNT_SERVICE.equals(name)) {
return getAccountManager();
} else if (POWER_SERVICE.equals(name)) {
return getPowerManager();
}
Android之getSystemService的更多相关文章
- android中getSystemService详解
android的后台运行在很多service,它们在系统启动时被SystemServer开启,支持系统的正常工作,比如MountService监 听是否有SD卡安装及移除,ClipboardS ...
- Android Service GetSystemService
http://blog.sina.com.cn/s/blog_71d1e4fc0100o8qr.html http://blog.csdn.net/bianhaohui/article/details ...
- Android——getSystemService
android的后台运行在很多service,它们在系统启动时被SystemServer开启,支持系统的正常工作,比如MountService监 听是否有SD卡安装及移除,ClipboardServi ...
- Android操作系统服务(Context.getSystemService() )
getSystemService是Android很重要的一个API,它是Activity的一个方法,根据传入的NAME来取得对应的Object,然后转换成相应的服务对象.下面介绍系统相应的服务: 传入 ...
- Android -- getSystemService
Android的后台运行在很多service,它们在系统启动时被SystemServer开启,支持系统的正常工作,比如MountService监听是否有SD卡安装及移除,ClipboardServic ...
- Android:getContext().getSystemService()
一.介绍 getSystemService是Android很重要的一个API,它是Activity的一个方法,根据传入的NAME来取得对应的Object,然后转换成相应的服务对象 二.语法 Windo ...
- android window(二)从getSystemService到WindowManagerGlobal
在Activity调用getSystemService(WINDOW_SERVICE) 调用的是父类ContextThemeWrapper package android.view; public c ...
- 【Android】 context.getSystemService()浅析
同事在进行code review的时候问到我context中的getSystemService方法在哪实现的,他看到了一个ClipBoardManager来进行剪切板存储数据的工具方法中用到了cont ...
- Android指纹解锁
Android6.0及以上系统支持指纹识别解锁功能:项目中用到,特此抽离出来,备忘. 功能是这样的:在用户将app切换到后台运行(超过一定的时长,比方说30秒),再进入程序中的时候就会弹出指纹识别的界 ...
随机推荐
- Builder 建造者模式 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- Gson解析复杂Json数据
背景 json是一种数据格式,便于数据传输.存储.交换. gson是 ...
- VS2008:Failed to return new Code Element
VS2008添加自动化类,报错: [解决方法1] This can be fixed by installing SP1. Please see https://connect.microsof ...
- Grunt学习一:使用grunt创建jquery plugin.
下载安装github客户端. http://windows.github.com 打开github客户端. 登录后,点击左上角的加号,可以创建一个Repository. (也可以点击Clone,将 ...
- [Node.js]29. Level 6: Socket.io: Setting up Socket.io server-side & Client socket.io setup
Below we've already created an express server, but we want to start building a real-time Q&A mod ...
- Foreda8上安装CMake2.8.1.2
本机操作系统:Linux 2.6.23.1-42.fc8 #1 SMP Tue Oct 30 13:55:12 EDT 2007 i686 i686 i386 GNU/Linux 在本机上准备安装My ...
- 自定义cas客户端核心过滤器AuthenticationFilter
关于cas客户端的基本配置这里就不多说了,不清楚的可以参考上一篇博文:配置简单cas客户端.这里是关于cas客户端实现动态配置认证需要开发说明. 往往业务系统中有些模块或功能是可以不需要登录就可以访问 ...
- Intent跳转到系统应用中的拨号界面、联系人界面、短信界面及其他
现在开发中的功能需要直接跳转到拨号.联系人.短信界面等等,查找了很多资料,自己整理了一下. 首先,我们先看拨号界面,代码如下: Intent intent =new Intent(); intent. ...
- MySQL 联合索引测试
搭建测试环境 1:创建表 CREATE TABLE tab_index (id int(5), age int(3), dte datetime); 2:插入测试数据 INSERT INTO tab_ ...
- ORA-14402:更新分区关键字列将导致分区更改(分区表注意)
建立完分区表后一定要和开发确认一点,就是是否会修改分区字段.因为update分区字段到其他分区时候,会报错.解决办法:开启表的行转移功能 alter table XX enable row movem ...