You need to get an instance of the SharedPreferences.Editor and carry out all your operations on it.
Try this. SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit(); editor.putString( "DrinkName" , "chai"); editor.commit(); SharedPreferences prefs = getPreferences(MODE_PRIVATE); String favdrink = prefs.getString( "DrinkName" , "" ); //it should return chai Every call to getPreferences( MODE_PRIVATE ).edit() is returning a new instance of the SharedPreferences.Editor object which is never being committed, hence you don't see your values being saved. For more details, check out http://developer.android.com/reference/android/content/SharedPreferences.Editor.html Hope this helps, Balwinder Kaur Open Source Development Center ·T· · ·Mobile· stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. On Jun 22, 8:15 pm, bear123434...@comcast.net wrote: > I have a screen where a user can enter information about a Favorite drink. I > want to save it to be recalled in the current an future sessions, but the > save doesn't seem to be working. Here is my code where I do the save. > > getPreferences( MODE_PRIVATE ).edit().putString( "DrinkName" , FavName); > > getPreferences( MODE_PRIVATE ).edit().putFloat( "Volume" , ( float ) AlcVol); > > getPreferences( MODE_PRIVATE ).edit().putFloat( "Percent" , ( float ) > AlcPerc); > > getPreferences( MODE_PRIVATE ).edit().commit(); MODE_PRIVATE > ).edit().putString( "DrinkName" , FavName); > > getPreferences( MODE_PRIVATE ).edit().putFloat( "Volume" , ( float ) AlcVol); > > getPreferences( MODE_PRIVATE ).edit().putFloat( "Percent" , ( float ) > AlcPerc); > > getPreferences( MODE_PRIVATE ).edit().commit(); MODE_PRIVATE > ).edit().putFloat( "Volume" , ( float ) AlcVol); > > getPreferences( MODE_PRIVATE ).edit().putFloat( "Percent" , ( float ) > AlcPerc); > > getPreferences( MODE_PRIVATE ).edit().commit(); MODE_PRIVATE > ).edit().putFloat( "Percent" , ( float ) AlcPerc); > > getPreferences( MODE_PRIVATE ).edit().commit(); MODE_PRIVATE > ).edit().commit(); > > Here is the code where I try to retrieve the saved infromation. > > String strName = getPreferences( MODE_PRIVATE ).getString( "DrinkName" , "" ); > > float fVolume = getPreferences( MODE_PRIVATE ).getFloat( "Volume" , ( float ) > 0.0); > > float fPercent = getPreferences( MODE_PRIVATE ).getFloat( "Precent" , ( float > ) 0.0); MODE_PRIVATE ).getString( "DrinkName" , "" ); > > float fVolume = getPreferences( MODE_PRIVATE ).getFloat( "Volume" , ( float ) > 0.0); > > float fPercent = getPreferences( MODE_PRIVATE ).getFloat( "Precent" , ( float > ) 0.0); float fVolume = getPreferences( MODE_PRIVATE ).getFloat( "Volume" , ( > float ) 0.0); > > float fPercent = getPreferences( MODE_PRIVATE ).getFloat( "Precent" , ( float > ) 0.0); float fPercent = getPreferences( MODE_PRIVATE ).getFloat( "Precent" , > ( float ) 0.0); > > When I retrieve the information, I always end up with the Default values. > > Does anyone have any ideas? > > Kevin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---