Tuesday, July 31, 2012

[android-developers] Re: SharedPreferences clarification

http://developer.android.com/reference/android/preference/PreferenceManager.html#getDefaultSharedPreferences(android.content.Context) 

On Tuesday, July 31, 2012 2:55:25 PM UTC+1, Sergio Panico wrote:
Hi all,
I need your help to have a clarification for the preferences framework of Android.

Accordingly to Google API Reference (http://developer.android.com/reference/android/preference/PreferenceActivity.html) I created my app preferences section by extending the PreferenceActivity class and by creating (sub)fragment for each different sections. It seems works well, but here is the first question:
  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. BTW, always for google gudelines, it is not a "best practice" to spread the setting into several section (http://developer.android.com/design/patterns/settings.html). So the question is, what of this two "techniques" is better to use? What is the criteria (for example number of settings...) to choose one or the other solution?

Then, assuming that i've choosen one of the technique and have implemented my preference section in my app, i know that all the settings are managed by Android with SharedPreference class. Now, I need to access to my settings outside the my PreferenceActivity class. I thought to work in this way: in my main Application class, I create a static method that, using the context of the app, accesses to the SharedPreferences object, retrive the setting I ask for, and return its value to the caller. But, the getSharedPreferences Context's method ask me for a "name" and a "mode". Accordingly to API reference "name" is "Desired preferences file" and "mode" is the "Operating mode". The question is:
  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)?

Thanks a lot for all the clarification
Regards
Sergio

--
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