I want to make a game level logic. The game itself similar with logo quiz game. It has locked and unlocked level. I need to display the locked and unlocked level based on the score which saved in shared preferences. so, how can I access the score variable in XML file?
Asked
Active
Viewed 500 times
1 Answers
0
declare these two variable in your activity
android.content.SharedPreferences someData;
public static String filename = "mySharedString";
initialize the Shared Preferences
like this:
someData = getSharedPreferences(filename, 0);
you can add elements to the Shared Preferences
like this:
android.content.SharedPreferences.Editor editor = someData.edit();
editor.putString("sharedString", stringData);
editor.commit();
you can retrieve data like this:
String dataReturned = someData.getString("sharedString","Couldn't load data");
The Couldn't load data
will be set to the dataReturned
variable if the sharedString
is not existed in the Shared Preferences
also check this question How to use SharedPreferences in Android to store, fetch and edit values

Community
- 1
- 1

William Kinaan
- 28,059
- 20
- 85
- 118