I am using Google Sign in for authentication. Following the tutorial, I am able to log in. Now I want to log out the user. I got the code for logging out. But how to do I know that the logout is success or fail?
private void signOut() {
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
// What code should I write here to see if the user has successfully logged out. If not, then I need to display an error message.
}
});
}
Google can return 5 types status. Following are the statuses along with the status codes:-
SUCCESS(0), INTERNAL_ERROR(8), INTERRUPTED(14), TIMEOUT(15), CANCELED(16)
So you can check for status.getStatusCode()
on logout and validate against the above mentioned statuses.
Just use
status.toString()
and log it to find out what details it contains. Then according to it you can use the below methods to check if you have been successfully logged out.
status.getStatusCode();
status.getStatusMessage();
Both methods are self explanatory.
I found a better approach to the question
Auth.GoogleSignInApi.signOut(googleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
// user logged out successfully
} else {
// the logout was not sucessful.
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.