Saturday, December 17, 2011

Re: [android-developers] SharedPreferences variable question

On Sat, Dec 17, 2011 at 11:22 PM, Larry/MavrickProductions <ohiooutofdoors@gmail.com> wrote:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences myPrefs = this.getSharedPreferences("settings", MODE_PRIVATE);
final SharedPreferences.Editor prefsEditor = myPrefs.edit();

final int setyear1 = prefs.getInt("setyear", 2036);

What am I missing?

Since you're creating two different instances of SharedPreferences without explanation, and getting the value from "prefs", the default one, I would have to guess that you're *setting* it in "myPrefs", the one that points to the "settings" preference.

Also, what is the point of "prefsEditor" ?

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment