public void retryAuthByUserRequest() {
   LOGD(TAG, "Retrying sign-in/auth (user-initiated).");
   if (!mGoogleApiClient.isConnected()) {
     sCanShowAuthUi = sCanShowSignInUi = true;
     PrefUtils.markUserRefusedSignIn(mAppContext, false);
     mGoogleApiClient.connect();
   } else if (!AccountUtils.hasToken(mAppContext, mAccountName)) {
     sCanShowAuthUi = sCanShowSignInUi = true;
     PrefUtils.markUserRefusedSignIn(mAppContext, false);
     mTokenTask = new GetTokenTask();
     mTokenTask.execute();
   } else {
     LOGD(TAG, "No need to retry auth: GoogleApiClient is connected and we have auth token.");
   }
 }
  /** Handles an Activity result. Call this from your Activity's onActivityResult(). */
  public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
    Activity activity = getActivity("onActivityResult()");
    if (activity == null) {
      return false;
    }

    if (requestCode == REQUEST_AUTHENTICATE
        || requestCode == REQUEST_RECOVER_FROM_AUTH_ERROR
        || requestCode == REQUEST_PLAY_SERVICES_ERROR_DIALOG) {

      LOGD(TAG, "onActivityResult, req=" + requestCode + ", result=" + resultCode);
      if (requestCode == REQUEST_RECOVER_FROM_PLAY_SERVICES_ERROR) {
        mResolving = false;
      }

      if (resultCode == Activity.RESULT_OK) {
        if (mGoogleApiClient != null) {
          LOGD(TAG, "Since activity result was RESULT_OK, reconnecting client.");
          mGoogleApiClient.connect();
        } else {
          LOGD(TAG, "Activity result was RESULT_OK, but we have no client to reconnect.");
        }
      } else if (resultCode == Activity.RESULT_CANCELED) {
        LOGD(TAG, "User explicitly cancelled sign-in/auth flow.");
        // save this as a preference so we don't annoy the user again
        PrefUtils.markUserRefusedSignIn(mAppContext);
      } else {
        LOGW(TAG, "Failed to recover from a login/auth failure, resultCode=" + resultCode);
      }
      return true;
    }
    return false;
  }