Note that there are some explanatory texts on larger screens.

plurals
  1. POalertDialog disclaimer shows on every run
    primarykey
    data
    text
    <p>I want to add an disclaimer to my app which pops up at the first start of the app. If the User declines, the app closes. If the user opens the app again the disclaimer should pop up again until the user accepts it. Once accepted it should hide and don't pop up anymore.</p> <p>My problem: If I accepted the disclaimer it closes and everything is fine. But when I launch the app it pops up again.</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final SharedPreferences pref = getSharedPreferences("Preferences", MODE_PRIVATE); 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) .setIcon(R.drawable.caution) .setPositiveButton("Accept", new DialogInterface.OnClickListener() { SharedPreferences.Editor edit = pref.edit(); public void onClick (DialogInterface dialog, int id) { boolean accepted = true; dialog.cancel(); if(accepted == true) { edit.putString("Version", this.getString(R.string.version)); edit.commit();} } private String getString(int version) { // I had to create this method, cause i got an error the line above this.getstring(R.string.version) return null; } }) .setNegativeButton("Decline", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MainActivity.this.finish(); } }); AlertDialog disc = builder.create(); disc.show(); } } </code></pre> <p>I found a <a href="https://stackoverflow.com/questions/11713073/one-time-alertdialog-showing-on-every-run">quite similar question</a>, but I couldn't solve my problem with it.</p> <p>I would be really happy about an answer and if possible a good explanation in the code. Cause I wanna learn more/why it solved my problem and don't want to copy &amp; insert a code and be happy that it works.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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