- Current user is set to a static helper class on login/registration or autologin
- Where needed in activity onCreate i get currentUser from my helper class by a getter.
- If after that currentUser is null, then i call the helper class initCurrentUser method, passing the activity instance as "this".
- The method accepts anything that implements my custom UserCallback like this:public static <T extends CustomUserCallback> void initUser(final T t)
- In it i try to get user from parse by ParseUser.getCurrentUser(); If ok then return the value via callback's method setUser(user) that sets the currentUser in the calling activity.
- If parse returns null user, then i try to login the user with saved auth data in shared preferences, and return the user via callback.
- If even the login fails, that means, most likely, that password was changed, then app goes to the login screen.
And in the activity i dont initialize views in onCreate method. The method initializing views is called when activity has a valid currentUser, from onCreate or from the setUser from the callback.
No comments:
Post a Comment