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 8916583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:16:19+00:00 2026-06-15T05:16:19+00:00

I created SharedPreference obj using following: Note : creating number of preferences under the

  • 0

I created SharedPreference obj using following:
Note : creating number of preferences under the same pref file name

public static Sting name = "abx"; //pref file name
          spo = context.getsharedpreference(name , mode_private);
          editor = spo.edit(); //get the editor associated with pref obj

         Map<String, String> test= new HashMap<String, String>();//create a map
    test.put("1", "abc");//fill the values
    test.put("2", "efg");//used map because values are stored in key -value pairs
    test.put("3", "ghj");
       for (String s : test.keySet()) {
        // use the name as the key, and the icon as the value
        editor.putString(s, nameIcons.get(s));//use the key as preference name
    }

    editor.commit();//commit the preferences

I have a doubt , please correct me if i am wrong , SharedPreference file with name “abz” is created and in this file preference values are stored as key – value pairs or if editor obj creates new preference file for each key , whats the use of supplying pref file name at the time of sharedprefences object creation?

  • 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-06-15T05:16:20+00:00Added an answer on June 15, 2026 at 5:16 am

    Essentially, you can create multiple preference files for a given application. There are a few reasons one could imagine doing this, the best being if you had multiple accounts. You could label one set of preferences “account1” and another “account2”. Just by keeping track of which account you are in, you can share code without a huge amount of complexity.

    Unless you are specifically using this functionality, I suggest you use context.getApplicationContext().getPackageName() for the name, as it should be available almost everywhere.

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

Sidebar

Related Questions

I created a following class within a namespace Global namespace Global { public static
I forgot the name of a SharedPreferences file that I created a while back.
I have created a custom listview that is populated using a row.xml file. Each
I created a python server on port 8000 using python -m SimpleHTTPServer . When
I wanted to know when is a shared preference file created for the first
I have created an activity where i have used shared preferences for storing data..now
I am new to android. I have created SharedPreferences to store a playlist name
I have some problem with my android project! I have created a preferences intent
When you createa a PreferenceScreen on Android, your application creates a default SharedPreferences file
Created .NET WCF service, tested it - works. Generated schemas from Data and service

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.