首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

getSharedPreferences(String name, int mode) of Service的兑现(转)

2012-09-09 
getSharedPreferences(String name, int mode) of Service的实现(转)I found a method getSharedPreferenc

getSharedPreferences(String name, int mode) of Service的实现(转)
I found a method getSharedPreferences(String name, int mode) in Service class

than I want to see how it implements

first I got a abstrat method in Context class

/android_opensource/frameworks/base/core/java/android/content/Context.java



but I still did't found where it pass the ApplicationContext in

after few minutes search I found another class ActivityThread

It had a method handleCreateService which should be called when create a Service

android_opensource/frameworks/base/core/java/android/app/ActivityThread.java


In the method it call the service's method attch and pass a ApplicationContext as parameter

then The service's attch method would pass the context throght the attachBaseContext(context) method
android_opensource/frameworks/base/core/java/android/app/Service.java
...50     /**51      * Set the base context for this ContextWrapper.  All calls will then be52      * delegated to the base context.  Throws53      * IllegalStateException if a base context has already been set.54      *55      * @param base The new base context for this wrapper.56      */57     protected void attachBaseContext(Context base) {58         if (mBase != null) {59             throw new IllegalStateException("Base context already set");60         }61         mBase = base;62     }...

so the service get the Context instance which implement the getSharedPreferences(String name, int mode) method

the original url http://hi.baidu.com/ksoftware/blog/item/de17bbd6806b202507088bd8.html

热点排行