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.
Share
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
step2: Reading with SharedPreferences object
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_prefsfolder