Business
Technology
- Administration
- Android
- Apache Solr
- API
- Development Principles
- Django
- Eclipse
- Hibernate
- Javascript/jQuery
- Microsoft .NET
- Microsoft Office
- Patterns
- PHP
- Social Media
- Spring 3.0
- Spring Roo
- Symfony
- Symfony: Doctrine
- Symfony: View
- Symfony: Web Services
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
Linus Torvalds
Android: Account Manager: Step by Step
Looking for an Android Developer?
If you or your company are looking for an Android Developer contact us or read about our Android Development Service
This is the second page of Android: Account Manager: Step by Step
Implement an Authenticator service
The authentication service extends the abstract android.app.Service class. An android service forms a component of the main application that signals to Android that the application wants to preform some task that may be long running or not necessarily require user interaction. One example could be a synchronization or in our case authentication. The documentation states that a service can be used by other applications so in our case we are going to have Android's Account manager connect to our application to fetch the users online account details.
Create a new class that extends the android.app.Service class.
Implement the onBind method to return an instance member of your AccountAuthenticator.
package au.com.finalconcept.tutorial.android;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class AuthenticatationService extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return new AccountAuthenticator(this).getIBinder();
}
}
This class is called by Android when the user clicks on your Account Authenticator in Android's Account Manager.
For now it will simply return back the account list when clicked.
Create the account authenticator xml
Create a new xml file in the res/xml directory called "authenticator.xml" with the following content
Thanks: to Marko for pointing out the typo with android:smallicon and android:accounttype. The below code has been updated
Change the label to use your own label stored in your strings.xml.
If you want your application to have preferences add the following line
android:accountPreferences="@xml/account_preferences"
For more information on preferences please read Android: Application Preferences
Register the service in the AndroidManifest.xml
The 5th and final part to getting your Account Authenticator to display in Android's Account Manager is to register the the Authenticator Service with Android. This is done by adding the following lines to your AndroidManifest.xml file.
If you found this article useful, please be sure to check out the related articles below.
Add a comment

Marko Salonen commented:
Really good and easy tutorial. But there is a small typo in the xml that confuses a little bit :-)
android:accounttype should android:accountType
and
android:smallicon should be android:smallIcon
Thanks for the good tutorial!
Adam Pullen commented:
Thanks Marko,
I have updated the article.
Rahul Choudhary commented:
Great piece of work, really nice. Thanks for sharing this
sandy commented:
Hi ,
I'm 6month into android.I wanted to know how to add an account in account manager in android through our application step by step
Adam Pullen commented:
Hello Sandy,
I am currently working on a project where this adding an account via the application will be undertaken.
As I move through the project i will write articles.
Should be within the next 2 weeks.
I will send you an email when I have completed each one.
Thanks
sandy commented:
Hi Adam,
I still didnt find solution for how to add an account in account manager
Adam Pullen commented:
Hello Sandy
Thanks for getting on to me about this.
I have finished the article on adding the account manager
http://www.finalconcept.com.au/article/view/android-account-manager-step-by-step-2
sendi_t34 commented:
AccountAuthenticator(this).getIBinder() throws excepton
sendi_t34 commented:
what is the package for class
AccountAuthenticator(this) ? in 2.2
Adam Pullen commented:
Good question.
The AccountAuthenticator is your custom class that extends AbstractAccountAuthenticator.
You can find out more about this class by reading the first part of the article. Found in the link below.
http://www.finalconcept.com.au/article/view/android-account-manager-step-by-step
I will update the article to include the "import" statement.
Ashwin commented:
Great piece of information.Very simple and informative!!! Just what i needed... :)
Alexander commented:
What theme is you using on your android making the background in the preferences screen in the android os white? Not the app you working with?
Pankaj Yadav commented:
Great information ,help me a lot ... thanks a lot
Jason commented: