Search code examples
androidgoogle-plus-signin

Google Plus Account Sign-In/Sign-Out not working properly


Not able to select among multiple accounts(second time and above) while sign in via google

I am using google plus sign in into my android app. Every thing is working fine. But when I try to login first time(after app installation) is gives me option to select among different google account(if i have more then 1 account login into my device) enter image description here, But when i logout and login again it don't give me that selection option, it automatically login with that account that was previously selected.

I am using this code for logout.

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).build();
            GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(context)
                    .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                    .build();
            Auth.GoogleSignInApi.signOut(mGoogleApiClient);
            Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient);

I have also gone through signOut documentation , What i understand from there is "Removes the default account set in Google Play services for your app" but it doesn't work. Is there any solution to do that ?

Anyone please help to find solution


Solution

  • After long time, i found the answer for the problem, from the answer of Rahul Sonone. They only thing that did trick for me is calling signOut just before you try to sign in.

    Auth.GoogleSignInApi.signOut(mGoogleApiClient);
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
    startActivityForResult(signInIntent, RC_SIGN_IN);