android哪个类为SharedReferences接口提供定义

android哪个类为SharedReferences接口提供定义,android,class,interface,sharedpreferences,Android,Class,Interface,Sharedpreferences,如果你看清楚了,就会发现它是Android SDK中的一个接口。 公共接口SharedReferences 谁能帮我更好地理解到底哪个类提供了函数的定义?这是一个接口,android文档中没有错误。正如您在的源代码中看到的: public interface SharedPreferences { 翻开android的源代码,我们可以看到它从ContextWrapper public class Activity extends ContextThemeWrapper impleme

如果你看清楚了,就会发现它是Android SDK中的一个接口。

公共接口SharedReferences


谁能帮我更好地理解到底哪个类提供了函数的定义?

这是一个接口,android文档中没有错误。正如您在的源代码中看到的:

public interface SharedPreferences {
翻开android的源代码,我们可以看到它从
ContextWrapper

public class Activity extends ContextThemeWrapper
    implements LayoutInflater.Factory2,
    Window.Callback, KeyEvent.Callback,
    OnCreateContextMenuListener, ComponentCallbacks2,
    Window.OnWindowDismissedCallback {
看看,它从
上下文
类调用
getSharedReferences
函数

Context mBase;

@Override
public SharedPreferences getSharedPreferences(String name, int mode) {
    return mBase.getSharedPreferences(name, mode);
}
在中声明为抽象函数

总之,
SharedReferences
是在每个
上下文
实现上的
(作为每个
接口
)中实现的。如果我们看一下
上下文中的注释
的源代码,我们可以看到:

这是一个抽象类,其实现由 安卓系统

如果您需要有关
上下文的更多信息,这里有更多信息:

getSharedReference()
ContextWrapper
类的函数。而
ContextWrapper
类由每个活动类扩展

当我们使用
getSharedReference()
方法时,它由上下文类调用。它位于上下文类对象中。但它返回
SharedReferences
对象。
共享首选项不是一个类,而是一个接口
getSharedReference()
是此接口的唯一引用

问题是关于的实现,我知道它的接口,但无法找到给它定义的类。感谢Santiago-它帮助我准确地理解我在寻找什么,但我不知道为什么有人对我的问题投反对票。不客气。是的,idk也是,但这里有+1给你
/**
 * 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);

}