Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PreviousActivity.userobj
- public class UserCreator
- {
- public static User getUser(Context context)
- {
- SharedPreferences prefs = context.getSharedPreferences("Name", Context.MODE_PRIVATE);
- //Check if the user is already stored, if is, then simply get the data from
- //your SharedPreference object.
- boolean isValid = prefs.getBoolean("valid", false);
- if(isValid)
- {
- String userName = prefs.getString("username", "");
- String passWord = prefs.getString("password", "");
- ...
- return new User(userName, passWord,...);
- }
- //If not, then store data
- else
- {
- //for example show a dialog here, where the user can log in.
- //when you have the data, then:
- if(...login successful...)
- {
- SharedPreferences.Editor editor = prefs.edit();
- editor.putString("username", "someusername");
- editor.putString("password", "somepassword");
- editor.putBoolean("valid", true);
- ...
- editor.commit();
- }
- // Now, if the login was successful, then you can recall this function,
- // and it will return a valid user object.
- // if it was not, then it will show the login-dialog again.
- return getUser(context);
- }
- }
- }
- User user = UserCreator.getUser(this);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement