I have the following code in my onActivityForResult
method after I add a contact using an intent.
if (mySharedPrefs.getBoolean("settingsPopup", false) == false) { //First time
new AlertDialog.Builder(this)
.setTitle("Go to settings? ")
.setMessage("POPUP")
.setNegativeButton("No", null)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent settingsIntent = new Intent(MainActivity.this, Settings.class);
startActivity(settingsIntent);
}
}).show();
myEditor = mySharedPrefs.edit();
myEditor.putBoolean("settingsPopup", true);
myEditor.commit();
}
I want this popup to only show once, which is why I set the shared preference key value "settingsPopup" to true after I first show the dialog. For some reason though, the dialog shows every time the onActivityForResult
method gets called. Why does it show every time?
PS: I am using the same shared preference object for storing other values.
Edit
I initialize my shared prefs in onCreate
like so:
mySharedPrefs = this.getSharedPreferences("sharedPrefsName", MainActivity.MODE_PRIVATE); //Making a shared preferences