Tuesday, July 31, 2012

Re: [android-developers] SharedPreferences clarification

On Tue, Jul 31, 2012 at 9:55 AM, Sergio Panico <sergio.panico@gmail.com> wrote:
> 1. Google API documentation talks about 2 "styles" for creating preference
> sections of an app: one "deprecated" old style, and one "newest" technique
> fragment-based. As per my understanding, with the first "old" method, all
> the settings belong to only one "screen", instead with the second it is
> possibile to create headers and subsection for grouping the settings.

The old method had its own way of doing headings and nested screens.
The new way offers more flexibility courtesy of the fragment system.

> So the
> question is, what of this two "techniques" is better to use?

Both, since the new PreferenceFragment system does not work on older
devices. For a modest number of preferences, you can use a single
implementation that works on old and new devices, but you do not get
the nested screens on API Level 10 and down. If you have too many
preferences to put into a single screen, you may need to have two
complete sets of preference XML files, one set optimized for each

> What is the
> criteria (for example number of settings...) to choose one or the other
> solution?

That is up to you.

> 2. How can I know what is the preference file for my application, as was
> the Android framework that managed the preferences for me (within my
> PreferenceActivity class)?

As RichardC noted, use getDefaultSharedPreferences() on PreferenceManager.

Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android Training in DC: http://marakana.com/training/android/

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
For more options, visit this group at

No comments:

Post a Comment