即使在sharedpreferences android中设置为true之后也会变为false

时间:2017-05-25 10:44:21

标签: android

 public void inValidMobileNumber() {

    if (TokenUtils.isInvalidDob() ) {
        startActivity(new Intent(PersonalInfo.this,PassTwo.class));
        overridePendingTransition(R.anim.dashboard_right_from,R.anim.dashboard_right_to);
        TokenUtils.setisInvalidDob(false);
    }
    else {
        TokenUtils.setisInvalidDob(true);
        Intent intent = new Intent(PersonalInfo.this, MobileNumber.class);
        intent.putExtra("reportId", reportId);
        intent.putExtra("activityCode", CreditMantriConstants.TELL_US_MORE_ACTIVITY);
        startActivity(intent);
        overridePendingTransition(R.anim.dashboard_right_from, R.anim.dashboard_right_to);
    }

}

public static void setisInvalidDob(Boolean dob){         SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CreditMantriApplication.getCreditMantri());         final SharedPreferences.Editor edit = preferences.edit();         edit.putBoolean(" DOB",DOB);         edit.apply();     }

public static Boolean isInvalidDob()
{
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CreditMantriApplication.getCreditMantri());
    return preferences.getBoolean("dob",false);
}

这是我的第二次获得invalidDob

的代码

1 个答案:

答案 0 :(得分:1)

使用

edit.commit();

而不是

edit.apply();

as edit.commit(); edit.apply();在后台做