SharedPreference doesn't save on Android -


i working sharedpreference cannot save info.

these code:

import android.app.activity; import android.content.context; import android.content.sharedpreferences; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.textview; import android.widget.toast;  public class sharedprefapp extends activity implements view.onclicklistener {  button buton1 , buton2 ; edittext etv1 , etv2 ; textview tv1; private static sharedpreferences sharedpref; protected void oncreate(bundle bambam){     super.oncreate(bambam);     setcontentview(r.layout.sharedpref_xml);     buton1 = ( button) findviewbyid(r.id.button12);     buton2 = ( button) findviewbyid(r.id.button13);     etv1= (edittext) findviewbyid(r.id.edittext4);     etv2= (edittext) findviewbyid(r.id.edittext5);     tv1 = (textview) findviewbyid(r.id.textview12);     buton1.setonclicklistener(this);     buton2.setonclicklistener(this); }  public void onclick(view v) {     switch (v.getid()){         case r.id.button12:             sharedpref = getsharedpreferences("namapassword" , context.mode_private );             sharedpreferences.editor editor = sharedpref.edit();             editor.putstring("isim" , etv1.gettext().tostring());             editor.putstring("sifre" , etv2.gettext().tostring());             editor.apply();             toast.maketext(this , "kaydedildi" , toast.length_short).show();             break;         case r.id.button13:             sharedpref = getsharedpreferences("namepassword" , context.mode_private);             string = sharedpref.getstring("isim", "olmadı");             string b = sharedpref.getstring("sifre" , "olmadı");             tv1.settext(a + " " + b);             toast.maketext(this, "gosterildi" , toast.length_short).show();             break;     } } 

}

it returns olmadı olmadı in application. why doesn't work?

it looks post code please add more details.

you have typo in code. spelled name nama, resulting in trying store , fetch values 2 different preferences.

your first button (r.id.button12) call shared preferences is:

sharedpref = getsharedpreferences("namapassword" , context.mode_private ); 

change to:

sharedpref = getsharedpreferences("namepassword" , context.mode_private ); 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -