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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:52:02+00:00 2026-06-08T15:52:02+00:00

I want some variables to be saved, when I shut down my app and

  • 0

I want some variables to be saved, when I shut down my app and to load them after opening the app (for statistics in a game)

How can I do this?

EDIT: Here my code:

TextView test1;
String punkte = "15";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    SharedPreferences save = getSharedPreferences(punkte, 0);
    save.edit().putString("score", punkte);

    SharedPreferences load = getSharedPreferences(punkte, 0);
    String points = load.getString("score", "0");

    test1 = (TextView) findViewById(R.id.test1);
    test1.setText(points);

    }    
  • 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-08T15:52:06+00:00Added an answer on June 8, 2026 at 3:52 pm

    You should be using SharedPrefences. They are quite simple to use and will store the variables in the application data. As long as the user never hits “Clear Data” in the settings for your application, they will always be there.

    Here is a code sample.

    To access variables:

    SharedPreferences mPrefs = getSharedPreferences("label", 0);
    String mString = mPrefs.getString("tag", "default_value_if_variable_not_found");
    

    To edit the variables and commit (store) them:

    SharedPreferences.Editor mEditor = mPrefs.edit();
    mEditor.putString("tag", value_of_variable).commit();
    

    Make sure both “tag” fields match!

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

Sidebar

Related Questions

I have some variables like these: a(1)=00:26:00 a(2)=744:32:00 a(3)=8040:33:00 I want to convert them
I have added some custom variables to customer and I want to use them
I want to define some variables depend on whether it is run on Iphone
I want to declare some global variables and global constants. Normally, I would put
Basically I have some variables that I don't want to preinitialize: originalTime = None
I want to declare some application level variables. These variables changes with values on
I have some user-submitted variables that I want to display in a different part
I have a bunch of variables I want to display of which some are
It's a new app I want to build, but I would like some ideas,
I want to post some text with image on Facebook wall. I have this

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.