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

  • Home
  • SEARCH
  • 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 8469959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:22:41+00:00 2026-06-10T16:22:41+00:00

I want to save input values so that they can be recalled when the

  • 0

I want to save input values so that they can be recalled when the application is restarted. Using this tutorial as a guide. I wrote the following code but am not having success getting the values to be recalled. Any help is greatly appreciated thank you.

Save Preferences method

public void SavePreferences(String key, String value){
    SharedPreferences portfoliopreferences = getPreferences(MODE_PRIVATE);
    SharedPreferences.Editor editor = portfoliopreferences.edit();
    editor.putString(key, value);
    editor.commit();
}

Save Preferences input

if(users.contains(usernull)){
    pn1 = enterportfolioname.getText().toString();
    denomination1 = denomination;  
    portfoliocurrency1 = portfoliocurrency;
    user1 = new PortfolioRecord(pn1, denomination1+df.format(portfoliovalue1));
    users.remove(usernull);
    users.add(user1);
    portfoliosdelete.add(pn1); 
    adapterdeletetype.notifyDataSetChanged();
    portfoliolist.invalidateViews();
    SavePreferences("U1C", "ýes");
    SavePreferences("PN1", enterportfolioname.getText().toString());
    SavePreferences("DN1", denomination);
    SavePreferences("PC1", "usd");
}

Load Preferences

public void LoadPreferences(){
    SharedPreferences portfoliopreferences = getPreferences(MODE_PRIVATE);
    String isuser1created = portfoliopreferences.getString("U1C", "");
    if(isuser1created.equals("yes")){           
        String savedportfolioname = portfoliopreferences.getString("PN1", "");
        String saveddenomination = portfoliopreferences.getString("DN1", "");
        String savedporfoliocurrency = portfoliopreferences.getString("PC1", ""); 
        pn1 = savedportfolioname;
        denomination1 = saveddenomination;
        portfoliocurrency1 = currencyUSD;
        user1 = new PortfolioRecord(pn1, denomination1+portfoliovalue1);        
        users.add(user1);
        portfoliosdelete.add(pn1); 
        calculateportfoliovalue1();
        adapterdeletetype.notifyDataSetChanged();
        portfoliolist.invalidateViews();
    }
}
  • 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-10T16:22:42+00:00Added an answer on June 10, 2026 at 4:22 pm

    The problem is simply that “ýes” does not equal “yes”:

    SavePreferences("U1C", "ýes");
    ...
    if(isuser1created.equals("yes"))
    

    So you never execute the code inside this block… (Change one or the other.)


    Also you create a new editor and run commit() each time you want to save one value. While it executes, this is slower than necessary.

    You should keep a class wide reference to portfoliopreferences and only call commit() once:

    SharedPreferences.Editor editor = portfoliopreferences.edit();
    editor.putString("U1C", "ýes");
    editor.putString("PN1", enterportfolioname.getText().toString());
    editor.putString("DN1", denomination);
    editor.putString("PC1", "usd");
    editor.commit();
    

    And you create Strings to that one don’t use:

    String savedportfolioname = portfoliopreferences.getString("PN1", "");
    String saveddenomination = portfoliopreferences.getString("DN1", "");
    ...
    pn1 = savedportfolioname;
    denomination1 = saveddenomination;
    

    You can skip over these:

    pn1 = portfoliopreferences.getString("PN1", "");
    denomination1 = portfoliopreferences.getString("DN1", "");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to ensure certain input into my webapp contains only characters that can
I want to save values as an ArrayList of double in a file. Whenever
I want to save a matrix to a text file, so I can read
I want to save and load my xml data using XmlReader. But I don't
I have a function that I want to use to manipulate an input parameter,
I have a bunch of partials that I want to render horizontally, using form-inline
I have an input and on blur I want to save the value. The
I have a form that the user inputs values that i save in an
The problem is this.I want to save every message in MySQL DB and I
I want to set some default values in my wordpress theme options, so that

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.