Мне нужно чтобы при закрытии программы удалялось значение и когда захожу снова, то все будто с нуля
public void onClick(View view) {
SharedPreferences sp = getSharedPreferences(MY_SETTINGS, Context.MODE_PRIVATE);
boolean flag = sp.getBoolean("Flag",false);
if(!flag){
Log.d(LOG_TAG, "IF");
//Timer
new CountDownTimer(6000, 1000) {
public void onTick(long millisUntilFinished) {
// mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
window();
textView.setText("Timer out");
}
}.start();
//Timer
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean("Flag",true);
editor.apply();
}
else{
Log.d(LOG_TAG,"ELSE");
}
}
@Override
public void onDestroy(){
Log.d(LOG_TAG,"onDestroy");
SharedPreferences sp = getSharedPreferences(MY_SETTINGS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.remove("Flag");
editor.apply();
}
public void window(){
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Important message!")
.setMessage("Timer out")
.setCancelable(false)
.setNegativeButton("Ok, shit",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Log.d(LOG_TAG,"onClick in window");
SharedPreferences sp = getSharedPreferences(MY_SETTINGS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.remove("Flag");
editor.apply();
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}}