Java – addAccount is not called from the AbstractAccountAuthenticator implementation of MainActivity

addAccount is not called from the AbstractAccountAuthenticator implementation of MainActivity… here is a solution to the problem.

addAccount is not called from the AbstractAccountAuthenticator implementation of MainActivity

I’m following tutorial for adding user accounts to Android AccountManager。

In my main activity, I have the following approach:

private void addNewAccount(String accountType, String authTokenType) {
    Log.d(TAG,"addNewAccount called");
    final AccountManagerFuture<Bundle> future = mAccountManager.addAccount(accountType, authTokenType, null, null, this, new AccountManagerCallback<Bundle>() {
        public void run(AccountManagerFuture<Bundle> future) {
            try {
                Bundle bnd = future.getResult();
                Log.d("ACME", "AddNewAccount Bundle is " + bnd);

} catch (Exception e) {
    }, null);

This method is being called, as I see in logcat logs. Now my AbstractAccountAuthenticator implementation is as follows:

public class AcmeAuthenticator extends AbstractAccountAuthenticator {

private String TAG = "AcmeAuthenticator";
private final Context mContext;

public AcmeAuthenticator(Context context) {
    this.mContext = context;

public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException {
    Log.d("acme", TAG + "> addAccount");

final Intent intent = new Intent(mContext, AuthenticatorActivity.class);
    intent.putExtra(AuthenticatorActivity.ARG_ACCOUNT_TYPE, accountType);
    intent.putExtra(AuthenticatorActivity.ARG_AUTH_TYPE, authTokenType);
    intent.putExtra(AuthenticatorActivity.ARG_IS_ADDING_NEW_ACCOUNT, true);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);

final Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    return bundle;

The above methods are never called. Here’s the service I created for:

public class AcmeAuthenticatorService extends Service {
public IBinder onBind(Intent intent) {

AcmeAuthenticator authenticator = new AcmeAuthenticator(this);
    return authenticator.getIBinder();

My list is defined as follows:

<activity android:name="com.exercise.accountmanagerstudy.accountAuthenticator.AuthenticatorActivity" android:label="@string/login_label"/>
    <service android:name=".accountAuthenticator.AcmeAuthenticatorService">
            <action android:name="android.accounts.AccountAuthenticator" />
        <meta-data android:name="android.accounts.AccountAuthenticator"
            android:resource="@xml/authenticator" />
<!-- client -->
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>

<!-- Authenticator -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>

I didn’t get a compiler error and didn’t call the addAccount override in the AbstractAccountAuthenticator implementation. The addNewAccount method from the main activity. I’ve looked at links here and here .
Any help would be appreciated.


Okay, so I finally figured it out. Obviously, AcmeAuthenticator’s authenticator.xml file has a field called accountType:

<?xml version="1.0" encoding="utf-8"?>

When I call addNewAccount in my main activity, I should pass the exact value of accountType in the above xml as the accountType parameter. ew, this took me a lot of time, hope it helps others :-).

Related Problems and Solutions