androidgoogle-api-clientgoogle-signingoogle-plus-signinandroid-googleapiclient

android google sign in window doesn't pop again after logout


On my Android app I have a Google Plus sign-in button in my MainActivity. I use these lines in my onCLick() method:

mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(Plus.API, Plus.PlusOptions.builder().build())
                .addScope(Plus.SCOPE_PLUS_LOGIN)
                .build();

mGoogleApiClient.connect();

And the first time I press the button a sign-in window comes up. I log in successfully with my google account into HomeActivity, and then successfully logout, using this 2 lines:

Plus.AccountApi.clearDefaultAccount(AppController.getInstance().getmGoogleApiClient());
mGoogleApiClient.disconnect();

(I tried to put mGoogleApiClient.connect(); as a 3rd line.. it didn't change anything)

So then I return to MainActivity, but when I press the sign-in Button again, it automatically signs me in back to HomeActivity, without popping up the sign-in window like the first time... although I alledgedly signed-out...

Does someone know what else should I add to my code? Or perhaps there is a way to manually show that sign-in window? What makes it pop the first time?

Thank you very much!


Solution

  • You need to add the following code at Log out, so it will clear all user data from your app, and after re-login you will get popping up the sign-in window like the first time.

    public void signOutFromGplus() {
        if (mGoogleApiClient.isConnected()) {
            Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
            Plus.AccountApi.revokeAccessAndDisconnect(mGoogleApiClient);
            mGoogleApiClient.disconnect();
            mGoogleApiClient.connect();
        }
    }