How can I use SharedPreferences on Android Studio to save some data like the value of a boolean?
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME,MODE_PRIVATE).edit();
editor.putBoolean("firststart",false);
editor.apply();
SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME,MODE_PRIVATE);
boolean firstStart= prefs.getBoolean("firststart",false);
if (!firstStart) {
Intent intent12 = new Intent(getApplicationContext(),FirstStart.class);
startActivity(intent12);
prefs.getBoolean("firststart",true);
}
else if (firstStart) {
}
If I use this code everytime I create the activity the value of the boolean return false and then true. How can I resolve this problem and don't lose the data?