Shared Preferences not evaluating correctly?
Of course it's not 1-for-1 code correct, but the gist of my question can be gleaned from this. Why is the result of my if statement always true? I'm guessing it has something to do with the file encoding of the preferences file? I'v开发者_JAVA百科e tried adding .toString() to the end of both. I have dumped a Toast out to see that "2.4" and "2.4" is what is returned.
if (appPrefs.getAppVer() != getAppVerName()) {
//TODO display Changes Pop-up
}
public String getAppVer() {
return appSharedPrefs.getString("appVer", "");
}
public String getAppVerName() {
return getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
}
Because you need to use .equals
and not !=
for string compares.
Always compare Strings with string1.equals(string2)
精彩评论