Reputation: 556
Making a app that asks user to create a profile, wondering where I should get started in having the app remember this data user inputs? Any tutorials or suggestions would be appreciated.
Thanks, Grant
Upvotes: 2
Views: 4045
Reputation: 69
Checked out SharedPreferences. Some examples here: SharedPreferences Tutorial
If you only have one user at once and just need to store simple user data like user name, email, id, you can store string/int/... format data in it. Or if you have server for storing user data, you can store credentials in SharedPreference and use the credentials to get data from your server.
Upvotes: 0
Reputation: 3099
I suggest you use SharedPreferences, unless you have a lot of information to store. After the user successfully logged in, store his information in your Preferences.
For example, to store the username :
private SharedPreferences mPreferences;
mPreferences = getSharedPreferences("User", MODE_PRIVATE);
SharedPreferences.Editor editor = mPreferences.edit();
editor.putString("username", your_user_name);
editor.commit();
Each time the user accesses the login activity, you can check if the username is already stored in the preferences :
if (mPreferences.contains("username")) {
// start Main activity
} else {
// ask him to enter his credentials
}
When the user logs out, don't forget to delete the username key from your preferences :
SharedPreferences.Editor editor = mPreferences.edit();
editor.clear(); // This will delete all your preferences, check how to delete just one
editor.commit();
Upvotes: 3
Reputation:
Insert the data to a SQLite database or use a plain file. The former is recommended for big apps.
Upvotes: 0