getSystemService,
分享于 点击 30789 次 点评:80
getSystemService,
frameworks/base/core/java/android/app/Activity.java
frameworks/base/core/java/android/app/ContextImpl.java
frameworks/base/core/java/android/content/Context.java
frameworks/base/core/java/android/content/ContextWrapper.java
frameworks/base/core/java/android/view/ContextThemeWrapper.java
其中ContextWrapper,ContextImpl,都继承自Context。而Context没有实现getSystemService。
public abstract Object getSystemService(String name);
Activity继承自ContextThemeWrapper,ContextThemeWrapper继承自ContextWrapper。ContexWrapper也是调用的父类的getSystemService。
所以getSystemService基本上都是调用的ContexImpl中的实现。
/**
* Common implementation of Context API, which provides the base
* context object for Activity and other application components.
*/
class ContextImpl extends Context {
private final static String TAG = "ApplicationContext";
@Override
public Object getSystemService(String name) {
ServiceFetcher fetcher = SYSTEM_SERVICE_MAP.get(name);
return fetcher == null ? null : fetcher.getService(this);
}
static {
registerService(STORAGE_SERVICE, new ServiceFetcher() {
public Object createService(ContextImpl ctx) {
try {
return new StorageManager(ctx.mMainThread.getHandler().getLooper());
} catch (RemoteException rex) {
Log.e(TAG, "Failed to create StorageManager", rex);
return null;
}
}});
扩展阅读:
http://www.360doc.com/content/12/0229/23/6541311_190694454.shtml
Override Context.getSystemService()
getSystemService() in Android
相关文章
- 暂无相关文章
用户点评