Skip to content Skip to sidebar Skip to footer

Best Way To Store A Single User In An Android App?

I'd like my app to allow a single user to create a profile that is accessed every time they run the app. The user's profile contains a String entry and five int entries. I've thoug

Solution 1:

Yes you can use SharedPreferences.

To write

Editoreditor= getSharedPreferences("file_name", MODE_PRIVATE).edit();
editor.clear();
editor.putString("pref_name", myStringValue);
editor.commit();

To read back

SharedPreferencespreferences= getSharedPreferences("file_name", MODE_PRIVATE);
StringmyStringValue= preferences.getString("pref_name", "default_value");

Regards.

Post a Comment for "Best Way To Store A Single User In An Android App?"