gpt4 book ai didi

android - 我无法从我的模块引用 SharedPreferences

转载 作者:行者123 更新时间:2023-12-02 12:07:17 25 4
gpt4 key购买 nike

我在我的项目中创建了一个模块。该模块的名称为“连接器”。现在我在 MainActivity 中创建

    private SharedPreferences sPref;
private SharedPreferences.Editor editor;
sPref = getPreferences(MODE_PRIVATE);

并填写数据。

editor.putString("sessionId", user.getSession().getSession());
editor.putString("userUuid", user.getUuid());
editor.apply();

现在我需要从模块“Connector”中的 SharedPreferences 获取数据。问题是模块“Connector”连接到应用程序

 compile project(':connector')

以及其中的类无权访问项目中的类。我该如何解决?

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.facebook.android:facebook-android-sdk:3.22.0'
compile 'com.google.android.gms:play-services:6.5.87'
compile project(':balanced-android')
compile project(':connector')
}

最佳答案

getPreferences 检索 SharedPreferences 对象,用于访问 Activity MainActivity 私有(private)的首选项。这只是通过传入此 Activity 的类名作为首选项名称来调用底层 getSharedPreferences(String, int) 方法。

您可以使用 getSharedPreferences。

了解更多信息 https://developer.android.com/reference/android/app/Activity.html

关于android - 我无法从我的模块引用 SharedPreferences,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28598083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com