Android - AccountManager and Login classic
<p>Today my application has a classic login screen (username and password), this class extends a common Activity. And my initial activity is to Login (if the already user is logged in it redirects to home).</p>

<p>My android manifest:</p>

<pre><code>    &lt;!-- Start Activity --&gt;
    &lt;activity
        android:name=".activity.LoginActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar"
        android:windowSoftInputMode="adjustPan"&gt;
        &lt;intent-filter&gt;
            &lt;action android:name="android.intent.action.MAIN" /&gt;
            &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
        &lt;/intent-filter&gt;
    &lt;/activity&gt;
</code></pre>

<p>And now I'm trying to deploy the Account Manager of Android, read the documentation and implemented. The feature is ok. If you enter the Android account settings, it is possible to login to the App and it created an account. But my question is how to keep both ways.</p>

<p>As facebook, if the user opens the application, it will log in and is automatically created an account on the AccountManager, and get it in accounts in the settings is also logged in the application. After I request the User validation and password on the server (using volleyball), how should I know what step to accomplish? Return the data to the AccountManager or add an account?</p>

<p>Login classic, after the server validation add the account using "addAccountExplicitly":</p>

<pre><code>   private void finishLogin(final String email, final String authToken) {
        Account account = new Account(email, AccountGeneral.ACCOUNT_TYPE);
        boolean success = mAccountManager.addAccountExplicitly(account, "", null);
        if (success) {
            Log.d(TAG, "Account created");
            mAccountManager.setAuthToken(account, mAuthTokenType, authToken);
        } else {
            Log.d(TAG, "Account creation failed. Look at previous logs to investigate");
        }
}
</code></pre>

<p>And login on the Account Settings:</p>

<pre><code>Bundle data = new Bundle();
        data.putString(AccountManager.KEY_ACCOUNT_NAME, email);
        data.putString(AccountManager.KEY_ACCOUNT_TYPE, accountType);
        data.putString(AccountManager.KEY_AUTHTOKEN, authToken);
        data.putString(PARAM_USER_PASS, password);
        final Intent intent = new Intent();
        intent.putExtras(data);

        final Account account = new Account(email, accountType);

        if (getIntent().getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT, false)) {
            Log.d(TAG, " finishLogin &gt; addAccountExplicitly");
            // Creating the account on the device and setting the auth token we got
            // (Not setting the auth token will cause another call to the server to authenticate the user)
            mAccountManager.addAccountExplicitly(account, password, null);
            mAccountManager.setAuthToken(account, mAuthTokenType, authToken);
        } else {
            Log.d(TAG, " finishLogin &gt; setPassword");
            mAccountManager.setPassword(account, password);
        }

        setAccountAuthenticatorResult(intent.getExtras());
        setResult(RESULT_OK, intent);
        finish();
</code></pre>