android提供定义到SharedPreferences接口 [英] android which class provide definition to SharedPreferences interface
问题描述
如果查看 SharedPreferences ,它会清楚地显示它是Android中的界面SDK。
public interface SharedPreferences
if look at SharedPreferences it clearly shows it's an interface in Android SDK.
public interface SharedPreferences
任何人都可以帮助我更好地理解哪个类提供了 SharedPreferences ?
Can anyone help me understand it better that which class exactly provides definition to functions of SharedPreferences?
推荐答案
这是一个接口,在android的文档中没有错误。如您在 SharedPreferences
的源代码:
It is an interface, there's no mistake in android's documentation. As you can see in SharedPreferences
's source code too:
public interface SharedPreferences {
在Android的源代码中,我们可以看到 活动
延伸自 ContextWrapper
Digging in android's source code, we can see that Activity
extends from ContextWrapper
public class Activity extends ContextThemeWrapper
implements LayoutInflater.Factory2,
Window.Callback, KeyEvent.Callback,
OnCreateContextMenuListener, ComponentCallbacks2,
Window.OnWindowDismissedCallback {
查看 ContextWrapper.java ,它从上下文
类
Context mBase;
@Override
public SharedPreferences getSharedPreferences(String name, int mode) {
return mBase.getSharedPreferences(name, mode);
}
被声明为抽象
函数在 Context.java ,
/**
* Interface to global information about an application environment. This is
* an abstract class whose implementation is provided by
* the Android system. It
* allows access to application-specific resources and classes, as well as
* up-calls for application-level operations such as launching activities,
* broadcasting and receiving intents, etc.
*/
public abstract class Context {
public abstract SharedPreferences getSharedPreferences(String name, int mode);
}
结束 SharedPreferences $每个
上的
在
类中实现
(如每个接口
/ code>实现。如果我们来看看 Context
的源代码中的注释,我们可以看到:
In conclusion SharedPreferences
is implemented in a class
(as every interface
) on every Context
implementation. If we take a look at the comments in Context
's source code we can see that:
这是一个抽象类,它的实现由
Android系统提供
This is an abstract class whose implementation is provided by the Android system
有关上下文
的更多信息,这里是更多的信息: Android中的上下文是什么?
And in case that you want more information about Context
, here is way more info: What is Context in Android?
这篇关于android提供定义到SharedPreferences接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!