Note that there are some explanatory texts on larger screens.

plurals
  1. POOne-time AlertDialog showing on every run
    text
    copied!<p>I am trying to have a disclaimer pop up when the app is first run, and after each update. I did a bunch of googling and reviewed some questions here as well, and this is what my code looks like:</p> <pre><code>SharedPreferences pref = getSharedPreferences("Preferences", MODE_PRIVATE); SharedPreferences.Editor edit = pref.edit(); String lver = pref.getString("Version", ""); String ver = this.getString(R.string.version); if(ver != lver) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Disclaimer") .setMessage(this.getString(R.string.disclaimer)) .setCancelable(false) .setPositiveButton("Accept", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { accepted = true; dialog.cancel(); } }) .setNegativeButton("Decline", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MainMenu.this.finish(); } }); AlertDialog disc = builder.create(); disc.show(); if(accepted == true) { edit.putString("Version", this.getString(R.string.version)); edit.commit(); } } </code></pre> <p>This code actually worked at first, but when I changed my apps starting activity, and moved this code from the original starting activity to the new one, it no longer works. The disclaimer appears on every run.</p> <p>I want the popup only to show on first run and after updates. What do I need to do to achieve this? I am very frustrated and confused by the fact that it was working, then wasnt.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload