i am trying to store the user preference whether he checks the checkbox or not ,but when i restart the activity, i am not able to restore the preference. here's what i have tried .
public void onCreate() { checkbox=(CheckBox)findViewById(R.id.checkbox); // storing the user preference SharedPreferences sharedpref = getApplicationContext().getSharedPreferences(MYPREF,Activity.MODE_WORLD_READABLE); // here MYPREF is the name of the file storing the preference SharedPreferences.Editor e = sharedpref.edit(); e.putBoolean("checkboxvalue", checkbox.isChecked()); e.commit(); //retrieving the preference set SharedPreferences mysharedpref = getApplicationContext().getSharedPreferences(MYPREF,Activity.MODE_WORLD_READABLE); checked=mysharedpref.getBoolean("checkboxvalue", false); if(checked)checkbox.setChecked(true); } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en