hi, i have an app in which i want to store the user preference that
whether he checks a chekckbox or not, however when i restart the app,
i am unable to restore the settings set by the user.
I have tried the following :
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en