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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:40:56+00:00 2026-06-09T16:40:56+00:00

I am using the shared preferences editor to store numbers to save and use

  • 0

I am using the shared preferences editor to store numbers to save and use in another class with in my project, this is my source to save the data:

public void overallEditor(){
        SharedPreferences.Editor editor = someData.edit();
        editor.putInt("winsOverall", winsOverall);
        editor.putInt("losesOverall", losesOverall);
        editor.putInt("tiesOverall", tiesOverall);
        editor.commit();
    }

this is my source that retrieves the data:

private void getStats() {
        // TODO Auto-generated method stub
        SharedPreferences someData = getSharedPreferences(filename, 0);
        bestStreakStatsi = someData.getInt("newBestStreak", 0);
        winsOverall = someData.getInt("winsOverall", 0);
        tiesOverall = someData.getInt("tiesOverall", 0);
        losesOverall = someData.getInt("losesOverall", 0);
    }

What is happening

enter image description here

this is my source from my first class, if you need more from my source i can provide it but i cut out what is irrelevant:

int wins, ties, loses, choice, streak, bestStreak, z, winsOverall, losesOverall, tiesOverall;

    private void refresh(){
            winrep.setText(w + wins);
            loserep.setText(l + loses);
            tierep.setText(t + ties);
            SharedPreferences.Editor editor = someData.edit();
            editor.putInt("winsp", wins);
            editor.putInt("losesp", loses);
            editor.putInt("tiesp", ties);
            editor.putInt("streakp", streak);
            editor.commit();
            overallEditor();
        }
        public void overallEditor(){
            SharedPreferences.Editor editor = someData.edit();
            editor.putInt("winsOverall", winsOverall);
            editor.putInt("losesOverall", losesOverall);
            editor.putInt("tiesOverall", tiesOverall);
            editor.commit();
        }

this is where it should be retrieving the ints:

public class stats extends Activity{
    public static String filename = "stats";
    TextView bestStreakStats, overallWins, overallLoses, overallTies;
    int bestStreakStatsi, winsOverall, losesOverall, tiesOverall;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.stats);
        initizialize();
        getStats();
        displayStats();
    }
    private void displayStats() {
        // TODO Auto-generated method stub
        bestStreakStats.setText("You best winning streak: \t" + bestStreakStatsi);
        overallWins.setText("Your overall wins: \t" + overallWins);
        overallLoses.setText("Your overall loses: \t" + overallLoses);
        overallTies.setText("Your overall ties: \t" + overallTies);
    }
    private void getStats() {
        // TODO Auto-generated method stub
        SharedPreferences someData = getSharedPreferences(filename, 0);
        bestStreakStatsi = someData.getInt("newBestStreak", 0);
        winsOverall = someData.getInt("winsOverall", 0);
        tiesOverall = someData.getInt("tiesOverall", 0);
        losesOverall = someData.getInt("losesOverall", 0);
    }
    private void initizialize() {
        // TODO Auto-generated method stub
        bestStreakStats = (TextView) findViewById(R.id.tvBestStreakStats);
        overallWins = (TextView) findViewById(R.id.tvOverallWins);
        overallLoses = (TextView) findViewById(R.id.tvOverallLoses);
        overallTies = (TextView) findViewById(R.id.tvOverallTies);
    }
}
  • 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-09T16:40:57+00:00Added an answer on June 9, 2026 at 4:40 pm

    I think that your problem is that you are referencing the wrong variable. You are saying.

    overallWins.setText("Your overall wins: \t" + overallWins);
    

    But I think it should be:

    overallWins.setText("Your overall wins: \t" + winsOverall);
    

    The same thing goes for the rest of the .setText. See if that helps.

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

Sidebar

Related Questions

I'm writing login capability using share preference. I use SharedPreferences.Editor::commit() to store username and
I am using shared preferences to save 3 string fields. I am opening shared
i am implementing one game application in this application i am using shared preferences
I am using shared preferences to store the number of times my application has
I want to clear value stored in Shared preferences I am using this code.
I created a sample application using Android TextView with shared preferences . In my
I'm using SharedPreferences to persists Object fields. Take this example: class Item { private
I am using boost shared pointers in my program, and I have a class
I am using default application preferences to store information related to my app. Basically
My app has the ability to backup and restore SharedPreferences using an BackupAgentHelper class.

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.