I want to display alertDialog only once. The first time user clicks on the play button, alertDialog should appear. User can stop the game. If he wishes to play again,the alertDialog should not appear again.
I've tried using sharedPreferences, but alertDialog is never displayed.
public boolean added = false;
private void startRoute(MenuItem item) {
SharedPreferences prefs = getContext().getSharedPreferences("myPref",Context.MODE_PRIVATE);
boolean added = prefs.getBoolean("added",false);
if(!added)
{
addRouteToCal();
}
refreshProgress();
}
private void addRouteToCal() {
final EditText taskEditText = new EditText(getContext());
new AlertDialog.Builder(getContext())
.setTitle(getString(R.string.current_add_to_favorites))
.setMessage(getString(R.string.current_name_favorites))
.setView(taskEditText)
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String name=String.valueOf(taskEditText.getText());
saveRouteDone(name);
SharedPreferences.Editor prefs = getContext().getSharedPreferences("myPref",Context.MODE_PRIVATE).edit();
prefs.putBoolean("added",true);
prefs.commit();
}
})
.setNegativeButton(getString(R.string.cancel), (dialog, which) -> {
})
.show();
;
Any idea of what I did wrong ?