I want to create a game that counts the clicks made in 60 seconds and saves the record. I would like this record to be saved on the device even after the app is closed. Is there some kind of variable that allows me to do this?
Question posted in Android Studio
The official documentation can be found here.
The official documentation can be found here.
2
Answers
SharedPreferences
is probably the place to start with this. You can view Android documentation related to it here along with code examples: Save key-value dataThere are some other options for saving data in an Android app on the left pane of that page, but
SharedPreferences
is probably the most applicable based on your described use case.Android’s Shared Preferences seem to be the most relevant option for you.
Refer to the official documentation for an in depth look:
https://developer.android.com/training/data-storage/shared-preferences
These code samples should help you as well:
To save a value into the Shared Preferences:
Make sure to keep the key identical between placing values into the preferences and retrieving.