I want check value with boolean, when likeState is true
, show me true toast
and when likeState is false
, show me false toast
.
in my application every user just can for one time click on like button. when click on button likeState is true and save true state for all.
I write below codes, but not work me and not save state!
private SharedPreferences.Editor stateEditor;
private boolean likeState = false, reportState;
private String stateLike_TAG = "LIKE_STATE";
statePrefs = getSharedPreferences(stateLike_TAG, MODE_PRIVATE);
stateEditor = statePrefs.edit();
// set Preferences
likeState = statePrefs.getBoolean(stateLike_TAG, false);
if (!likeState) {
TastyToast.makeText(context, "Like, Thnx", TastyToast.LENGTH_LONG, TastyToast.ERROR);
stateEditor.putBoolean("liked", true);
}
I want to use sharedPreferences
to save the states, how can I do it?