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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:29:13+00:00 2026-06-02T00:29:13+00:00

I want to save some values before i closed the app. But i don’t

  • 0

I want to save some values before i closed the app. But i don’t know if i must create a new file(.txt) and save it in; or i just can change strings.xml file and when i open app next time the saved values will be the right saved values or will be walues which i define them before first using. I know that exist really easy way to read from strings.xml file and so i think that there must be a way to set values in this file before closing (but i can’t find on the net). Thanks for any examples or yours advice and explanation.

  • 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-02T00:29:15+00:00Added an answer on June 2, 2026 at 12:29 am

    Android provides the SharedPreferences class to help you save simple application data.
    You can use SharedPreferences class to save the config information or anything you want.
    When you put the application in background or close it, onStop() will be called. You can override it to implement what you want.

    Usage of SharedPreferences class is very simple:

    step 1: Writing with SharedPreferences object

    //Create a object SharedPreferences from getSharedPreferences("name_file",MODE_PRIVATE) of Context
    private SharedPreferences pref;
    pref = getSharedPreferences("info", MODE_PRIVATE);
    //Using putXXX - with XXX is type data you want to write like: putString, putInt...   from      Editor object
    Editor editor = pref.edit();
    editor.putString("key5","value5");
    //finally, when you are done saving the values, call the commit() method.   
    editor.commit()
    

    step2: Reading with SharedPreferences object

    //get SharedPreferences from getSharedPreferences("name_file", MODE_PRIVATE)
    SharedPreferences shared = getSharedPreferences("info",MODE_PRIVATE)
    //Using getXXX- with XX is type date you wrote to file "name_file"
     String string_temp = shared.getString("key5");
    

    The MODE_PRIVATE constant indicates that the shared preference file can only be opened by the application that created it.

    The shared preferences file is save as an XML file in /data/data/<package_name>/shared_prefs folder

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

Sidebar

Related Questions

I want to save some custom data into application configuration file and I need
I want to save to a log file some SQL query rails performs, (namely
I created a new attribute (multiple select) with some values, everything works fine but
In a java serialization problem, I want to save some classes name and I
I want to provide the ability to save some rendered data/charts (with the titles
i have some element in my container and want to save all properties of
i have a form with some checkboxes on it i want to save those
I want to save my program's DataModel objects to a file, and be able
I want to save a matrix to a text file, so I can read
I had not run into this before but I wanted to know if it's

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.