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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:34:32+00:00 2026-05-27T00:34:32+00:00

I have a sharedPreferences implementation where I store user preferences. When the user clicks

  • 0

I have a sharedPreferences implementation where I store user preferences. When the user clicks “preferences” in menu, I open the standar editor to allow the user to change preferences. This is the code:

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case R.id.MENU_PREFERENCES:
        Intent intent = new Intent(context, PreferencesActivity.class);
        startActivity(intent);
        return true;
    case xx:
                ....
    }
    Toast.makeText(this, "ERROR: Bad menu item", Toast.LENGTH_SHORT).show();
    return true;
}

In PreferencesActivity.java I have:

public class PreferencesActivity extends PreferenceActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
    }



}

My question is if can I have a variable in the preferences for internal use, I mean, that will not be showed to user when startActivity(intent)? how?

I suppose I must change something in preferences.xml but dont know exactly what….

thanks

EDIT: as requested, I paste xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
    <PreferenceCategory>
        <ListPreference android:title="Pomodoro duration" android:key="pomodoro_duration" android:summary="Duration of each pomodoro" android:entryValues="@array/array_duration_values" android:defaultValue="25" android:entries="@array/array_duration"/><ListPreference android:key="short_break_duration" android:title="Short break duration" android:summary="Duration of break after each pomodoro" android:entryValues="@array/array_duration_values" android:entries="@array/array_duration" android:defaultValue="5"/>
        <ListPreference android:title="Long break interval" android:summary="Interval of the longer break" android:key="intervalos" android:entryValues="@array/interval_array_values" android:defaultValue="4" android:entries="@array/interval_array"/>
        <ListPreference android:defaultValue="20" android:title="Long break duration" android:summary="Duration of break after each pomodoro" android:key="long_break_duration" android:entries="@array/array_duration" android:entryValues="@array/array_duration_values"/><RingtonePreference android:title="Notification sound" android:ringtoneType="notification" android:summary="Tone that will sound after pomodoro ends" android:key="notification_tone" android:showDefault="true" android:showSilent="true"/>
        <ListPreference android:summary="Period used to calculate productivity" android:title="Calculus period" android:key="calculus_period" android:entryValues="@array/array_calculo_valores" android:entries="@array/array_calculo"/>
      </PreferenceCategory>

</PreferenceScreen>

When I inveke the standar UI to allow user to set this variables, I would like to hide one of them programmaticaly. Is possible?

  • 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-27T00:34:32+00:00Added an answer on May 27, 2026 at 12:34 am

    If it is not in preferences.xml, it won’t be displayed, so just don’t add it there. You can use the SharedPreferences class to get/set preferences without displaying a UI. Something like:

    SharedPreferences prefs = PreferenceManager
                    .getDefaultSharedPreferences(context);
    boolean flag = prefs.getBoolean("flag", false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an IntentService which updates a preference like this: SharedPreferences.Editor editor = userPrefs.edit();
I have a string I want to store in my SharedPreferences. Is there some
For my application, I have a custom implementation of SharedPreferences . In API level
I have the following code in a method. This is the entire method: private
Most apps have some kind of preferences or user settings that can be stored
I am new to android. I have created SharedPreferences to store a playlist name
I have this code that should read an unset preference on the first run:
I have the following code: SharedPreferences KITPrefs; EditText passPhraseExample; ... @Override public void onCreate(Bundle
I have read this helpful post : SharedPreferences.onSharedPreferenceChangeListener not being called consistently However I
I have a question : So i have this line of code(i got it

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.