开发者

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜