title: Android Google Sign-In error on cancel
body: <p>I'm having some weird issue which I haven't been able to resolve. I have an Android app that has the Google sign-in. The app is following the MVP pattern and uses fragments instead of activities. The log-in part is from here:
  <a href="https://developers.google.com/identity/sign-in/android/" rel="noreferrer">https://developers.google.com/identity/sign-in/android/</a></p>
  
  <p>It works all fine until I try to dismiss the sign-in dialog (where you select the user) by tapping outside of it. I would assume that it should give me a status code 12501 (SIGN_IN_CANCELLED) but instead I'm getting code 13 (ERROR). Is my assumption wrong? Should I just ignore the code 13 and not show the user any error if it occurs?</p>
  
  <p>Below is the most relevant code</p>
  
  <p>Activity:</p>
  
  <pre><code>public class SignInActivity extends AppCompatActivity implements SignInFragment.SignInListener {    
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_sign_in);
  
          // Add sign in fragment
          mSignInFragment = new SignInFragment();
          FragmentManager fragmentManager = getSupportFragmentManager();
          fragmentManager
                  .beginTransaction()
                  .replace(R.id.sign_in_frame, mSignInFragment, TAG)
                  .commit();
      }
  
      @Override
      public void startSignIn() {
          Intent signInIntent = mSignInFragment.getGoogleSignInClient().getSignInIntent();
          startActivityForResult(signInIntent, RC_SIGN_IN);
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
  
          if (requestCode == RC_SIGN_IN) {
              Task&lt;GoogleSignInAccount&gt; task = GoogleSignIn.getSignedInAccountFromIntent(data);
              mSignInFragment.handleSignInResult(task);
          }
      }
  }
  </code></pre>
  
  <p>Fragment:</p>
  
  <pre><code>public class SignInFragment extends DaggerFragment implements SignInContract.View, GoogleApiClient.OnConnectionFailedListener {
  
      private SignInFragment.SignInListener signInListener;
  
      public interface SignInListener {
          void startSignIn();
          void startMainActivity();
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
          GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                  .requestIdToken( clientId )
                  .build();
  
          mGoogleSignInClient = GoogleSignIn.getClient(getActivity(), gso);
  
          // Calling this to force user select dialog to appear everytime
          mGoogleSignInClient.signOut();
  
          signInButton.setOnClickListener(v -&gt; {
              signInListener.startSignIn();
          }
      }
  
      protected void handleSignInResult(Task&lt;GoogleSignInAccount&gt; task) {
          try {
              GoogleSignInAccount acct = task.getResult(ApiException.class);
              String idToken = acct.getIdToken();
              presenter.deliverTokenToServer(idToken);
  
          } catch (ApiException e) {
              e.printStackTrace();
              Log.d(TAG, "handleSignInResult:" + e.getStatusCode());
              Snackbar snackbar = Snackbar.make(getView(), R.string.error_login_failed_try_again, Snackbar.LENGTH_LONG);
              snackbar.show();
  
          }
      }
  }
  </code></pre>
  
  <p>In the gradle files I've used <em>'com.google.android.gms:play-services-auth:15.0.1'</em> and <em>'com.google.gms:google-services:4.0.1'</em></p>