Reputation: 23
I am developping an app and the user authenticats with google sign in. Sign in is perfect but if I use
mAuth.signOut();
this signs me out of firebase and not from the google account. when I try to sign in it signs in with the account I used just before and I don't have the option to choose an account. I followed the google documentation to sign out user and disconnect accounts. my button code:
btnlogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
signOut();
}
});
my signOut code
private void signOut() {
mGoogleSignInClient.signOut()
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
startActivity(new Intent(TempActivity.this,MainActivity.class));
}
});
}
Button is inside onCreate. My app crashes when I Press the log out button. Any ideas? I get error when i call signout, java.lang.NullPointerException
Upvotes: 2
Views: 1431
Reputation: 162
You need to make sure you are referencing to the same GoogleSignInClient
object. It looks to me that you are using another GoogleSignInClient
object in the class that handles the logout which is not yet initialized and thereby causing a nullpointer exception.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
You then need to use the same reference to mGoogleSignInClient
in the class that handles the logout.
Upvotes: 1