how to retrieve int value from Sharedpreferences in Android -
i trying save , value sharedpreference far storing data concern working i'm helpless while retrieving value.
//setting constant
private static final string wallpaper_pref_file = "wallpaper";
//method storing key value pair
private void savewallpaper(int wallpaperid) { pref = getsharedpreferences(wallpaper_pref_file, mode_private); editor = pref.edit(); editor.putint("wallpaperid", wallpaperid1); editor.commit(); }
// call method getsharedpreferences() value in oncreate() of activity .
sharedpreferences getpreff = getsharedpreferences(wallpaper_pref_file, mode_private);
//default value
int resid1 = r.drawable.chat_composer; int resid = getpreff.getint("wallpaperid", resid1); //do operations resid
look have typo in retrieval - wallpaerid. fix , should work. (even better, use constant string in both saving , retrieving avoid problem).
Comments
Post a Comment