Search code examples
javaandroidgoogle-plusgoogle-signingoogle-plus-signin

Google plus 'choose account' choose account does not disappears on cancel?


I am trying to login with google plus and it works fine.I have more than one account assosiated with my account when so it show me the pop up to choose account but when i click on Cancel button then it does disappears.It appears again & again. Tell me the way how to do it?enter image description here

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
     if (requestCode == RC_SIGN_IN) 
     {
         Log.i("RAE","Result is  ");
            if (resultCode != RESULT_OK) {
              mSignInClicked = false;
            }

            mIntentInProgress = false;

            if (!mGoogleApiClient.isConnecting()) {
              mGoogleApiClient.connect();
            }
          }


}

On connection Failed

@Override
    public void onConnectionFailed(ConnectionResult result) {
        // TODO Auto-generated method stub
         if (!mIntentInProgress && result.hasResolution()) {
                try {
                  mIntentInProgress = true;
                  startIntentSenderForResult(result.getResolution().getIntentSender(),
                      RC_SIGN_IN, null, 0, 0, 0);
                } catch (SendIntentException e) {
                  // The intent was canceled before it was sent.  Return to the default
                  // state and attempt to connect to get an updated ConnectionResult.
                  mIntentInProgress = false;
                  mGoogleApiClient.connect();
                }
              }

    }

Solution

  • You aren't using the value for mSignInClicked in determining whether to startIntentSenderForResult() - this means that even if the user clicks the cancel button, you'll still call startIntentSenderForResult() again and again - add mSignInClicked to your if statement:

    if (!mIntentInProgress && mSignInClicked && result.hasResolution()) {
    

    If you'd still like an auto-sign in like experience on first launch, you should also set mSignInClicked to true in your onCreate() if savedInstanceState == null (i.e., the first time the activity is launched). This will ensure that startIntentSenderForResult() is done at least once each time the user launches the activity. Note: you may want to also set a shared preference stating that you attempted auto-login and not attempt to auto-login again if you already attempted to auto-login and they canceled.