PreferenceActivity help

Put your problem here if it does not fit any of the other categories.

PreferenceActivity help

Postby zackola » Wed Nov 19, 2008 5:52 am

So,

I want to be able to use SharedPreferences across different Activities in my app. I was doing this fine with a normal Activity that had a bunch of controls in a LinearLayout, and attaching to the OnClickListener events for each control and then commiting the preferences. Then in a different activity I coudl retreive those preferences using

getSharedPreferences(PREFS_NAME, 0);

where PREFS_NAME is a string defined in both activities.

This was going OK, but a little clunky...and then I found PreferenceActivity, and all its promised goodness of automatically handling the persistence of preferences. This is going fine, and values seem to be persisting within the PreferenceActivity, but I can't figure out how to get the preferences that are saved in my PreferenceActivity in other normal Activities.

I hope the answer to this is really simple. It probably is, but it's getting late and my brain is fried. Thanks in advance!
zackola
Freshman
Freshman
 
Posts: 2
Joined: Wed Nov 19, 2008 5:36 am

Top

Postby zackola » Wed Nov 19, 2008 6:33 am

As predicted and answering my own question, I think this does the trick.

PreferenceManager.getDefaultSharedPreferences(this);

Facepalm. http://www.forumammo.com/cpg/albums/use ... cepalm.jpg
zackola
Freshman
Freshman
 
Posts: 2
Joined: Wed Nov 19, 2008 5:36 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 14 guests