I am creating a game which uses google login to sign in into the app. So I wanted to store the info about the players the user has previously played with so that I could give him those suggestion while playing next time. Please explain in details how should I go about this problem.
Asked
Active
Viewed 21 times
1 Answers
0
The SharedPreferences class is exactly for this purpose, i.e. user settings
Setting values in Preference:
// MY_PREFS_NAME - a static String variable like:
//public static final String MY_PREFS_NAME = "MyPrefsFile";
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
editor.putString("name", "Elena");
editor.putInt("idName", 12);
editor.apply();
Retrieve data from preference:
SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
String name = prefs.getString("name", "No name defined");//"No name defined" is the default value.
int idName = prefs.getInt("idName", 0); //0 is the default value.
More info here
gtxtreme
- 1,219
- 1
- 7
- 20