You can enable your users to sign out of your app, and to disconnect their accounts from your app entirely.
Sign out users
To add a sign out button to your app, first create a button in your app to act
as your sign out button. Then, attach an
onClickListener
to the button and configure the onClick
method to call
signOut
.
@Override
public void onClick(View v) {
switch (v.getId()) {
// ...
case R.id.button_sign_out:
signOut();
break;
// ...
}
}
private void signOut() { mGoogleSignInClient.signOut() .addOnCompleteListener(this, new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { // ... } }); }
This code clears which account is connected to the app. To sign in again, the user must choose their account again.
Disconnect accounts
It is highly recommended that you provide users that signed in with Google the ability to disconnect their Google account from your app. If the user deletes their account, you must delete the information that your app obtained from the Google APIs.
The following code shows a simple example of calling the
revokeAccess
method:
private void revokeAccess() { mGoogleSignInClient.revokeAccess() .addOnCompleteListener(this, new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { // ... } }); }
In the completion listener, you can respond to the event and trigger any appropriate logic in your app or your back-end code.