title: Google Drive Account Picker onActivityResult resultCode is always -1
body: <p>I am currently working on an android application and I am trying to integrate Google Drive. I'm having a problem with the account picker, that when the account is chosen and it returns into the onActivityResult function the resultCode is -1 which I believe it should be 0 to mean that it was successful. </p>
  
  <p>Below is how I am opening the account picker</p>
  
  <pre><code>credential = GoogleAccountCredential.usingOAuth2(context, DriveScopes.DRIVE);
  startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER
  </code></pre>
  
  <p><code>credential</code> is a global variable so the whole class has access to this variable. </p>
  
  <p>Below is the code for the onActivityResult</p>
  
  <pre><code>else if (resultCode == REQUEST_ACCOUNT_PICKER)
  {
      if (resultCode == RESULT_OK &amp;&amp; intent != null &amp;&amp; intent.getExtras() != null)
      {
      String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
      SharedPreferences settings = context.getSharedPreferences("prefs", 0);
      SharedPreferences.Editor editor = settings.edit();
      editor.putString("google_drive_account_name", accountName);
      editor.putBoolean("drive_sync_upload_download_required", true);
      editor.commit();
      }
  }
  </code></pre>
  
  <p>It goes into the else if statement fine but when it checks if the resultCode equals RESULT_OK it returns false as the resultCode is for some reason being set to -1. I assume -1 means that something has failed but I can't see any error messages in the logCat. </p>
  
  <p>Thanks for any help you can provide. </p>