0

在我准备好部署之前,我的应用程序运行良好。我的应用程序的一部分用于检查首选项中是否选中了复选标记。好吧,因为我添加为库并且正在通过另一个应用程序运行(创建了应用程序的免费版本并试图将我的代码保留为库)它总是返回 false。

        SharedPreferences appPrefs = context.getSharedPreferences("com.company.widget_preferences", Context.MODE_PRIVATE);
    boolean blNotifications;
            blNotifications = appPrefs.getBoolean("notifications_new_message", false);

if (blNotifications)
{
   //always returns false
}

谢谢你的帮助。

4

1 回答 1

0

想通了伙计们。出于某种原因,使用SharedPreferences appPrefs = context.getSharedPreferences在开发中工作,但是一旦我将它变成图书馆,它就不再喜欢它了。调用默认共享首选项的正确方法如下。

SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
String value = pref.getString("name_of_my_pref", "default_value");

再次感谢。

于 2013-04-27T22:14:37.160 回答