【发布时间】:2016-05-03 22:23:51
【问题描述】:
有人在 Nexus 6P 设备上遇到过这个问题吗?我只在 Nexus 6P(运行 Google Fi)上遇到这个问题。
当我安装应用程序时,SharedPreferences 内有一个 userIsLoggedIn 的密钥。
这个块:
boolean userIsLoggedIn = SharedPrefs.userIsLoggedIn(this);
// Then in another class...
public static boolean userIsLoggedIn(Context context) {
// For users updating apps, if the previous key-value is a string, convert it to boolean
try {
return context.getSharedPreferences(LOGIN_FILE, Context.MODE_PRIVATE)
.getBoolean(USER_LOGGED_IN, false);
} catch (ClassCastException e) {
Logger.e(TAG, e.getMessage());
context.getSharedPreferences(LOGIN, Context.MODE_PRIVATE)
.edit()
.putBoolean(USER_LOGGED_IN, false)
.commit();
return context.getSharedPreferences(LOGIN, Context.MODE_PRIVATE)
.getBoolean(USER_LOGGED_IN, false);
}
}
现在这应该在新卸载时返回false,但在全新安装时调试它我在应用启动时得到以下信息。
如果这很重要,我也会运行 Proguard,当在未启用 proguard 的 APK 上运行设备时,它运行正常。在任何其他设备上运行 proguard 都可以正常运行。
【问题讨论】:
-
您检查过其他设备吗?代码看起来不错。
-
我认为 login 在代码中的某处是正确的,因为共享首选项的行为不是这样,所以请先检查一下。
-
这绝对不是问题,这段代码先运行。已在其他 8 台设备上确认。
标签: android sharedpreferences nexus-6p