Tuesday, February 19, 2013

on Leave a Comment

Parse API: Logout and the Current User's Session


After I completed my the login tutorial last week I continued work on my side project. Very early on I needed to keep my user logged in indefinitely (until they logged themselves out). Fortunately one of the added benefits of the Parse API and the ParseUser is that it automatically caches the ParseUser to local storage until ParseUser.logout() is called explicitly.

For example, if you were to take the Launcher activity from the previous tutorial and add in a brief bit of logic you can direct the user to the LoginActivity only if there is no ParseUser cached to local storage. Assuming the user has logged in previous and logout has not been called ParseUser.getCurrentUser() will return the user the Parse last cached to local storage.


That is it! If you ever want to log the user out and send them back to the login activity you can do so with something like the following code:


I hope this helps someone get a grasp on user management!
Powered by Blogger.