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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:57:41+00:00 2026-06-06T02:57:41+00:00

I have setup ability for a user to specify some settings using the in-built

  • 0

I have setup ability for a user to specify some settings using the in-built preference system. My preference.xml is simple, with only a ListPreference:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
  xmlns:android="http://schemas.android.com/apk/res/android" android:persistent="true">

    <PreferenceCategory android:title="Your nuSTOCK Settings" android:persistent="true">

    <ListPreference android:key="operation_section" android:entries="@array/array_nustock_section_values" android:summary="What's your operational section in nuSTOCK?" android:entryValues="@array/array_nustock_section_keys" android:title="Operation Section" android:negativeButtonText="Cancel" android:positiveButtonText="OK" android:persistent="true" android:enabled="true"/>

    </PreferenceCategory>

</PreferenceScreen>

That references my Arrays, which are:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string-array name="array_nustock_section_keys">
        <item>store</item>
        <item>branch</item>
    </string-array>
    <string-array name="array_nustock_section_values">
        <item>Store</item>
        <item>Branch</item>
    </string-array>

</resources>

And then I load it (the Preference Module) into my Activity Like this:

nustock_preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

After which I then prompt the user to set the values (select from only two options), by invoking the preference activity via an Intent:

Intent settingsActivity = new Intent(this,
                    MyPreferenceActivity.class);
            startActivity(settingsActivity);

The Preference Activity is like so:

public class MyPreferenceActivity extends PreferenceActivity {



    private static final String PREF_FILENAME = "nustock_preferences";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            getPreferenceManager().setSharedPreferencesName(PREF_FILENAME);
            addPreferencesFromResource(R.xml.preferences);            

    }
}

And I then try to read the preference value set by the user like this:

nustock_preferences = PreferenceManager
                .getDefaultSharedPreferences(getBaseContext());
        String op = nustock_preferences.getString(PREF_OPERATION_SECTION,"none");
        Log.d(Tag,String.format("Operation Section : %s", op));

PROBLEM:

No matter what value of the preference I select, only value I get is the default “none” (which I’ve actually added as different from the actual values in the list, just to highlight the problem — selected value never gets returned!).

So, What Am I doing wrong? I’ve tried many variations of this approach, but I can’t get the user’s selected preference! Even tried restarting the app (hoping that the preferences get set at start-up, nothing!)

But, interestingly, whenever I load the preference screen, the correct value is still selected under the ListPreference dialog!

  • 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-06T02:57:43+00:00Added an answer on June 6, 2026 at 2:57 am

    I believe you specify a particular preference file name with getPreferenceManager().setSharedPreferencesName(PREF_FILENAME);
    but later you are trying to get preference value from default preferences .getDefaultSharedPreferences(getBaseContext());

    It’s like writing data to table PERSON, but later trying to find it in the table DEFAULT

    Either remove the setting for preference file name, or get your value from the preference file you specified

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

Sidebar

Related Questions

I have setup some simple associations in my rails app: resources :properties do resources
I have a simple Ability.rb set up listed below: if user.role? :super_admin can :manage,
We have some bbcode and I'm trying to setup the ability for a certain
I have setup mappings for a number of classes, however in some scenarios I
I have setup hadoop on top of mongodb using hadoop-mongodb driver. Currently I can
I'm using DotNetOpenAuth as my membership system, and the way I have it working
I have a setup where a program gets its input like so: 1) user
I have setup airbrake in my app but it doesn't seem to log any
I have setup an app project and a static project in a workspace in
i have setup an overlay script to enable me to display an overlay popup

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.