java - If shared preferences does not contain -
sharedpreferences mprefs = getsharedpreferences("idvalue",0); if(mprefs.contains("date")) { //do }else { mprefs.edit().putstring("date", currentdate); mprefs.edit().commit(); toast.maketext(this, "changed", toast.length_short).show(); }
what want code run first time , show toast second time run not show , run code inside first parameters. code runs second "else" statement twice , doesn't run first. it's if string isn't being put in "date"? there wrong code?
make editor
object , use edit/commit.
you can use below code. work fine.
sharedpreferences mprefs = getsharedpreferences("idvalue",0); sharedpreferences.editor meditor = mprefs.edit(); if(mprefs.contains("date")) { //do }else { meditor.putstring("date", currentdate); meditor.commit(); toast.maketext(this, "changed", toast.length_short).show(); }
Comments
Post a Comment