If shared preferences does not contain

    SharedPreferences mPrefs = getSharedPreferences("IDvalue",0);

    if(mPrefs.contains("DATE")) {
    //do something
    }else {
        mPrefs.edit().putString("DATE", currentdate);
        Toast.makeText(this, "changed", Toast.LENGTH_SHORT).show();

What i want the code to do is run the first time and show the toast but the second time it is run not show it and run the code inside the first parameters. But as it is now the code just runs the second “else” statement twice and doesn’t even run the first. it’s as if the string isn’t even being put in “DATE”? Is there anything wrong with my code?

Source: java

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.