title: Android AccountManager addAccount throwing OperationCanceledException on callback
body: <p>I am developing an android app, using android studio (0.8.2) and API level 19.</p>
  
  <p>I have implemented authentication using AccountManager, but am running into an exception when attempting to retrieve the data from the AccountManagerFuture returned by the callback specified in AccountManager.addAccount. This behavior only occurs when addAccount is called from within my app, the onCreate of MainActivity to be precise. The error does not occur when the account is added through the android settings screen. Here is the code that calls addAccount:</p>
  
  <pre><code>mAccounts = mAccountManager.getAccountsByType(mAccountType);
      if (mAccounts.length == 0) {
          Log.d("MainActivity", "No accounts of type " + mAccountType);
          mAccountManager.addAccount(
                  mAccountType,
                  AUTHTOKEN_TYPE_FULL_ACCESS,
                  null,
                  new Bundle(),
                  this,
                  new OnAccountAddComplete(),
                  null
              );
      }
  </code></pre>
  
  <p>And here is the callback:</p>
  
  <pre><code>private class OnAccountAddComplete implements AccountManagerCallback&lt;Bundle&gt; {
      @Override
      public void run(AccountManagerFuture&lt;Bundle&gt; result) {
          Bundle bundle;
          try {
              bundle = result.getResult();
          } catch (OperationCanceledException e) {
              e.printStackTrace();
              return;
          } catch (AuthenticatorException e) {
              e.printStackTrace();
              return;
          } catch (IOException e) {
              e.printStackTrace();
              return;
          }
          mAccount = new Account(
                  bundle.getString(AccountManager.KEY_ACCOUNT_NAME),
                  bundle.getString(AccountManager.KEY_ACCOUNT_TYPE)
          );
          // do more stuff
      }
  }
  </code></pre>
  
  <p>These follow the pattern shown in this <a href="http://www.fussylogic.co.uk/blog/?p=1035">example</a>. The authentication system and activities closely follow the example given <a href="https://github.com/Udinic/SyncAdapter/tree/0c7d2ace4567c6a21bf47b5a66a41fb19038e8cf/src/com/udinic/sync_adapter_example/authentication">here</a>, in particular the Log In and Sign Up activities. The exception is logged between the end of the SignUpActivity(line 104) and the callback in the AuthenticatorActivity (line 81)</p>
  
  <pre><code>W/System.err﹕ android.accounts.OperationCanceledException
  W/System.err﹕ at android.accounts.AccountManager$AmsTask.internalGetResult(AccountManager.java:1503)
  W/System.err﹕ at android.accounts.AccountManager$AmsTask.getResult(AccountManager.java:1531)
  W/System.err﹕ at android.accounts.AccountManager$AmsTask.getResult(AccountManager.java:1452)
  W/System.err﹕ at com.example.project.app.MainActivity$OnAccountAddComplete.run(MainActivity.java:256)
  W/System.err﹕ at android.accounts.AccountManager$11.run(AccountManager.java:1427)
  W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:733)
  W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
  W/System.err﹕ at android.os.Looper.loop(Looper.java:136)
  W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5001)
  W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
  W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:515)
  W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
  W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
  W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>The call to <code>result.getResult</code> throws a <code>android.accounts.OperationCanceledException</code>. The documentation only indicates that a user intervention or other event has cancelled the operation. Despite this, the new account is created and added to the AccountManager, and can be successfully used by the app once reopened.</p>
  
  <p>This has been reproduced on different devices and workstations. Information on anything that would trigger the cancellation is also appreciated.</p>