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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:08:23+00:00 2026-06-13T07:08:23+00:00

I am a noob to android development and I am trying to use shared

  • 0

I am a noob to android development and I am trying to use shared preferences to get values for a double during onCreate. However, my code for doing this seems to only work the first time I restart my app. During, subsequent restarts the code doesn’t work and skips over the if/else portion of my code. This is very frustrating because if it works one time it should work every time. Any help is greatly appreciated.

public void LoadPreferences(){
                            double portfoliocurrency1 = null;
            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", ""); //<--Always either "usd", "inr", or "eur".
                Log.d("test","SPConLoad=" + savedporfoliocurrency ); //<--Returns correct value on every restart.
                Log.d("test","USD=" + currencyUSD ); //<--Returns correct value on every restart.
                Log.d("test","EUR=" + currencyEUR ); //<--Returns correct value on every restart.
                pn1 = savedportfolioname;
                denomination1 = saveddenomination;
                if(savedporfoliocurrency=="usd"){ //<--If/else statement only works on first restart.  For some reason it is skipped on subsequent restarts.
                    portfoliocurrency1 = currencyUSD; 
                    Log.d("test","PC1USD=" + currencyUSD ); //<--Returns correct value on first restart.
                }else if(savedporfoliocurrency=="eur"){
                    portfoliocurrency1 = currencyEUR;
                    Log.d("test","PC1EUR=" + currencyEUR ); //<--Returns correct value on first restart.
                }else if(savedporfoliocurrency=="inr"){
                    portfoliocurrency1 = currencyINR; //<--Returns correct value on first restart.
                }
                Log.d("test","PC1onLoad=" + portfoliocurrency1 ); //<-- Only returns correct value during first restart.  Always returns null on subsequent restarts.
              }
  • 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-13T07:08:24+00:00Added an answer on June 13, 2026 at 7:08 am

    You should be using String.equals() here, not ==.

    if(savedporfoliocurrency=="usd"){
    

    See, for example, the SO question Java String.equals versus ==.

    ==, as you found, will work sometimes, but it’s not what you want to do here. You want to check the contents, not the location where they’re stored.

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

Sidebar

Related Questions

I am a noob to android development and i am trying to display rss
I'm a noob to android development and i am trying to remove a string
I'm a noob to Android development and i want to develop a game you
I'm a noob to android and I am trying to implement the 9 Old
I am a noob to android and i am trying to inflate two different
I'm kind of a noob at Android, and I downloaded some source code to
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initControls(); } I'm a noob android coder.
This is an Android noob question. I am trying to start an activity of
I'm a noob to Android, and I am trying to figure out how to
I am a noob to android and I am trying to update a sqlite

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.