Message from discussion
SharedPreferences clarification
Received: by 10.66.85.3 with SMTP id d3mr323732paz.18.1343743720701;
Tue, 31 Jul 2012 07:08:40 -0700 (PDT)
X-BeenThere: android-developers@googlegroups.com
Received: by 10.68.136.39 with SMTP id px7ls848899pbb.1.gmail; Tue, 31 Jul
2012 07:06:41 -0700 (PDT)
Received: by 10.66.74.197 with SMTP id w5mr2573915pav.1.1343743600989;
Tue, 31 Jul 2012 07:06:40 -0700 (PDT)
Received: by 10.66.74.197 with SMTP id w5mr2573914pav.1.1343743600980;
Tue, 31 Jul 2012 07:06:40 -0700 (PDT)
Return-Path: <mmur...@commonsware.com>
Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com [209.85.160.53])
by gmr-mx.google.com with ESMTPS id pz2si241174pbb.0.2012.07.31.07.06.40
(version=TLSv1/SSLv3 cipher=OTHER);
Tue, 31 Jul 2012 07:06:40 -0700 (PDT)
Received-SPF: pass (google.com: domain of mmur...@commonsware.com designates 209.85.160.53 as permitted sender) client-ip=209.85.160.53;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of mmur...@commonsware.com designates 209.85.160.53 as permitted sender) smtp.mail=mmur...@commonsware.com
Received: by mail-pb0-f53.google.com with SMTP id rr13so13362058pbb.40
for <android-developers@googlegroups.com>; Tue, 31 Jul 2012 07:06:40 -0700 (PDT)
d=google.com; s=20120113;
h=mime-version:in-reply-to:references:from:date:message-id:subject:to
:content-type:x-gm-message-state;
bh=GC4yEwJ1sY9uAEl8T6bA/lwfdKBO5iQ7DVd+AOY+mok=;
b=eMcsorq+6BmEm7f4CDVN890mCs+T53LwWGBOKggjfnNZqOiSS+dmngJafbnkGWPxP6
FQOy4THrDa8g3hVOXGxiKxtewoA+DyVm5JP02Ta/kFGOhguCCReGb3CzUu09yrndJjYw
cFoyd6U9X9U3nqRN2hvBUo3f+DScEOnGFG2smFdTQk6RySfO1EXJgnLzfqmps99k6u02
TPi95/NXjc6UUbBZvuHWv6xvq4HqeqQTfPM8IrRInqKV1ICLHzut+ime1Hz7Fumobo6w
THHk8YxVA6dVTuQYEI7JiR7MFAHYr/OmraXUMXQoIDT7Wxl6bJ5s1+Kq/WUDjoKy6jCW
5Fdw==
Received: by 10.68.201.9 with SMTP id jw9mr43925043pbc.28.1343743600395; Tue,
31 Jul 2012 07:06:40 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.143.139.5 with HTTP; Tue, 31 Jul 2012 07:06:10 -0700 (PDT)
In-Reply-To: <f0787d57-6153-4cfc-8191-b9e314023aa5@googlegroups.com>
References: <f0787d57-6153-4cfc-8191-b9e314023aa5@googlegroups.com>
From: Mark Murphy <mmur...@commonsware.com>
Date: Tue, 31 Jul 2012 10:06:10 -0400
Message-ID: <CALLdnhM8M05oaVhodLgLf7BkQUTHbio5z=ipdmhgX6RWaZA...@mail.gmail.com>
Subject: Re: [android-developers] SharedPreferences clarification
To: android-developers@googlegroups.com
Content-Type: text/plain; charset=ISO-8859-1
X-Gm-Message-State: ALoCoQlVqGj/0bGuSg1+Wi0HfxyUUgl6Fx+bCidbAajwJMyfevgEHXoCx0yILV6zhPlF6wkA/lJ3
On Tue, Jul 31, 2012 at 9:55 AM, Sergio Panico <sergio.pan...@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
technique.
> 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/