I want to add functionality like when user first time logged in then there is no need to re-enter e-mail and password rather than user can be logged in until he/she press the logout button.(Like Facebook,Google,...) How can i do this?
-
Maintain a session for user when logs in and terminate it on logout using shared preferences – Vivek Mishra Apr 04 '16 at 06:39
4 Answers
You can store a boolean value in shared preferences after a successfully login, and the next time, you can easily check this value, if its true, you can jump to the next activity, else user have to login again.
- 1,329
- 12
- 14
Why dont you save username and password in shared preferrence and send it in the header of all your web service call. When user taps on log out clear the shared preference. That being said is a temp patch, what is correct way then??? Maintaining session tokens.
Have you ever heard of OAuth??? Facebook, Google and Twitter makes use of OAuth version 2.0. (That was the last time I explored their API last year).
Implementing OAuth takes the logic implementation at server end.Here is the link to oAuth specs 2.0 if you really wanna understand the concepts of Access token, refresh token, Authorization token and all https://www.rfc-editor.org/rfc/rfc6749.
Not bothered to read :o then follow my first suggestion, save username and password in shared preference send it as request header for all the API that needs authentication and clear out shared preference on log out :)
- 1
- 1
- 19,999
- 5
- 45
- 78
From the Facebook API for Login on Android, "LoginManager class - To initiate login without using a UI element."
- 73
- 9
Use Boolean variable and after login make it true and store it in shared preference. So whenever application is started first check if that Boolean is true or not, if true directly jump to home page and if false intent to login page.
Same way you can also store username in shared preference
- 1,563
- 4
- 26
- 44