getDefaultSharedPreferences() returns the same preferences for every context, provided that getDefaultSharedPreferencesName() returns the same thing. The default string returned by getDefaultSharedPreferencesName() is the package name concatenated with "_preferences", which will be the same for every context associated with a component in your app.
The underlying getSharedPreferences() method takes a string, which is the unique set of preferences for that package. Any context in that application using that same string will be working with the same preferences (hence why they are shared). On Tue, Mar 16, 2010 at 2:21 PM, Bob Kerns <r...@acm.org> wrote: > BINGO! > > If you're using getDefaultSharedPreferences, you want to use > getApplication() to get the context to supply. > > The shared preference file name can differ if you use differing > contexts. You want to use the same context every time, no matter which > activity or service you look at it from. So you need the Application. > > Using adb (you may need a rooted phone or the emulator to do this), > look at /data/data/<pkgid>/shared_prefs, which is where the preference > files get created as .xml files. > > This will give you a much better understanding of how this works, and > will also let you more directly debug any problems. > > On Mar 15, 5:51 pm, "Matt (preinvent)" <m...@preinvent.com> wrote: > > One thing has just occurred to me. My app contains a service, an > > activity and a widget. Depending on what gets updated first, the > > database connection is instantiated using a Context from one of these. > > > > If it's instantiated with the Context from say the service, then at > > another point it's instantiated with the Context from the activity, > > will this cause me any problems? > > -- > 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+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en