Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6026115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:23:57+00:00 2026-05-23T04:23:57+00:00

I am working on implementing the preferences for our application. I know how to

  • 0

I am working on implementing the preferences for our application. I know how to display preferences UI and how to read/write values using SharedPreferences. In our app, I need to handle two sets of preferences and I would like to ask about this issue, one comment in the Android documents in particular.

The documentation for Preference.getSharedPreferences() has the following comment under the Return values section:

Returns The SharedPreferences where this Preference reads its value(s), or null if it isn’t attached to a Preference hierarchy.

I would like to ask how it is possible to attach a SharedPreferences to a particular Preference, be it EditTextPreference or others. In other words, how does the persistence code in a Preference know that it should store the user input in one particular SharedPreferences object and not the other?

To explain my question further with an example, suppose I have the following:

SharedPreferences prefs1 = getSharedPreferences(file1, mode);
SharedPreferences prefs2 = getSharedPreferences(file2, mode);

My question is what API I should use so that prefs1 is used by the Preference objects’ persistence code and not prefs2.

The target is Nexus One, running 2.3.4.

Maybe the answer is obvious but I could not find it after reading the documentation and searching the web. Thank you in advance for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:23:57+00:00Added an answer on May 23, 2026 at 4:23 am

    In other words, how does the persistence code in a Preference know that it should store the user input in one particular SharedPreferences object and not the other?

    Preference uses PreferenceManager‘s getSharedPreferences(), which eventually routes to getDefaultSharedPreferences().

    You are welcome to create your own Preference subclasses that change this behavior, but since the preference screen system may not be designed to handle multiple SharedPreference objects, there’s a chance that your preference changes might not get persisted.

    IOW, I encourage you to reconsider:

    In our app, I need to handle two sets of preferences

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on implementing the public API of our web application. The application
Working in Eclipse on a Dynamic Web Project (using Tomcat (v5.5) as the app
I have an Android application that I've been working on, and it's implemented using
We are working implementing Single Sign On(SSO) using pingfederate . The basic implementation uses
I'm working on a implementing a SNMP into a GWT project. I need to
I am working on an opengl application and implementing a bezier surface in the
I am working on implementing Zend Framework within an existing project that has a
I'm currently working on a Google Maps project and am implementing a search function.
I'm working on a project for school, and I'm implementing a tool which can
Working with python interactively, it's sometimes necessary to display a result which is some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.