我在比较字符串时遇到问题:我在 string.xml 中获得了“activation”的字符串值。当我将它与具有相同值的字符串值进行比较时,结果始终为假(在 string.xml 中激活 = 测试)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">MyNameApp</string>
<string name="activation">test</string>
</resources>
public class CheckGenuine {
public static String cod;
public static String app;
public static Boolean chk(Context ctx) {
Boolean ret;
cod = ctx.getString(R.string.activation);
app = ctx.getString(R.string.app_name);
if (cod == "test") {
Toast.makeText(ctx, "True cod = " + cod, Toast.LENGTH_LONG).show();
ret = true;}
else {
Toast.makeText(ctx, "False cod = " + cod, Toast.LENGTH_LONG).show();
ret = false;}
// *** why ret is always false and Toast shows "False cod = test" ????????????????
return ret;
}
}