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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:37:17+00:00 2026-06-12T00:37:17+00:00

The program creates preferences the first time but after that it never changes them.

  • 0

The program creates preferences the first time but after that it never changes them. I would appreciate assistance in understanding why.

This is the PreferencesScreen where the xml is called.

public class PreferencesScreen extends PreferenceFragment{

private final String TAG = "PreferencesScreen";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "OnCreate");
    addPreferencesFromResource(R.xml.prefs);
}

In the preferences I have a ListPreference and a Preference which calls an activity to store emails.

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

<PreferenceCategory android:title="Information Collected">
    <ListPreference 
        android:key="loggins"
        android:title="Logs Stored"
        android:summary="Choose the top kind of logs do you want to store."
        android:dialogTitle="Choose Logs"
        android:entries="@array/logs"
        android:entryValues="@array/logsValues"/>
</PreferenceCategory>

 <PreferenceCategory android:title="Email Configurations">
        <Preference
              android:key="pushing"
              android:title="The Email Activity"
              android:summary="Just push">
             <intent android:action = "ADDING_EMAIL"/>
        </Preference>
 </PreferenceCategory>
</PreferenceScreen>

Everything until here. The problems are in the activity called…

public class AddingEmail extends ListActivity implements OnClickListener{       

private Set<String> emails; 
private EditText emailAdd;
SharedPreferences.Editor editor;

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addingemail);
    Button add = (Button) findViewById(R.id.add);
    emailAdd = (EditText) findViewById(R.id.email);
    prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    editor = prefs.edit();

    prefList = toArrayList(prefs.getStringSet("emailWrongs", null));
    add.setOnClickListener(this);
}


public void onClick(View v) {
    Set<String> list = prefs.getStringSet("emailWrongs", null);
    String newEmail = emailAdd.getText().toString();        
    if (list==null){  //first time the preferences are called. 
        emails = new TreeSet<String>();
        editor.putStringSet("emailWrongs", emails);
        editor.apply();
    }
    if (newEmail != ""){
        emails=prefs.getStringSet("emailWrongs", null);
        emails.add(newEmail);
        editor.putStringSet("emailWrongs", emails);
        editor.apply();
    }
}

}

The point is that it always stores the first time well but if I when I add another email the preferences doesnt’t change. They looks like they change because if I printed them they show all the emails I add but the preference file doesn’t change (Checking it in the File Explorer). And if i reboot or close and open again, the preferences are only with the first email I add.
The thing is if i back to and change the preference of the ListPreference, then it stores all the changes even the emails I added.

Hope I was clear, it has a lot of code because i wanted to be very explicit.
Thank you for the 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-06-12T00:37:18+00:00Added an answer on June 12, 2026 at 12:37 am

    After more than a week looking for the mistake I found it.
    I think this can be helpful for a lot of people who had the same trouble.

    The problem was that when I call the preferences to get the String Set, it only reference the list and not make a copy of it. So I have to create a new list and add all the elements stored before and also add the new element and then with the editor change the preferences with the new list.
    The code is like this:

    Set<String> list = prefs.getStringSet("emailWrongs", null); 
    Set<String> newList = new TreeSet<String>();
    String newEmail = emailAdd.getText().toString();         
    if (newEmail != ""){ 
        if (list != null){
            for(String each: list){
                newList.add(each);
            }
        }
        newList.add(newEmail);
        editor.putStringSet("emailWrongs", newList);     
        editor.apply();      
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

use this website a lot but first time posting. My program creates a number
my program creates expandable Lists, and I have implemented swipes- but I cant figure
I have made a program that scans rss feeds. This same program creates feeds
With win32api, I want that the following program creates two process and creates a
In Form1 I have PageControl. At run time my program creates tab sheets. In
I have a program that creates multiple text files of rdf triples. I need
I have a program that creates a JFrame and makes it visible. Is there
I have a program that creates a small file in the Bin directory for
My solution is primarily C#, but I have one C++ project that creates a
Suppose my program creates a large array of data which I then save with

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.