I've seen AccountManager in the Android SDK and that it is used for storing account information. Thus, I cannot find any general discussion of what it is intended for. Does anyone know of any helpful discussions of what the intention behind AccountManager is and what it buys you? Any opinions of what type of Accounts this is suitable for? Would this be where you'd put your user's account information for a general web service?
This question is a bit old, but I think it is still of good interest.
AccountManager
, SyncAdapter
and ContentProvider
go together.
SyncAdapter
without an Account
in the AccountManager
.SyncAdapter
without a ContentProvider
.But you can:
ContentProvider
without the others.AccountManager
without the others (but you cannot use an AccountManager
without a SyncAdapter
before Android 2.2 / Froyo API 8)With AccountManager
/ SyncAdapter
/ ContentProvider
:
AccountManager
gives users a central point (Settings > Accounts) to define their credentialsSyncAdapter
. This can be good to optimize battery (no sync is done when network is down, for instance)ContentProvider
is a convenient way to share data across applications
Note: there are other methods of inter-process communication on Android.ContentProvider
schedules the database access in a background threadAsyncQueryHanlder
helps to query the ContentProvider
in a background thread, preventing Application Not Responsive (ANR) errors while not requiring you to explicitly handle threading.ContentProvider
ties into ContentResolver
's observer: this means it is easy to notify views when content is changedBottom line: the framework AccountManager
/ SyncAdapter
/ ContentProvider
helps if you want to synchronize data from a web resource. Fake/Dumb implementations are required on API 7. Also
AsyncTaskLoader
Finally, if you use a SyncAdapter
, seriously consider Firebase Cloud Messaging (previously Google Cloud Messaging) aka "push notifications" to have fresher updates and optimized battery usage.
The AccountManager class is integrated with your phone accounts. So if you follow all the guides and get it working correctly you'll see your accounts under the menu "Settings->accounts and sync". From there you can customize them or even delete them. Furthermore the accountManager has a cache of the authentication tickets for your accounts. This can be used also if you don't plan to synchronize your account (as far as I know).
If you don't want your accounts to appear under that menu you shouldn't use the AccountManager and store the accounts data elsewhere (maybe in the shared preferences) http://developer.android.com/guide/topics/data/data-storage.html
From http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/:
The first piece of the puzzle is called an Account Authenticator, which defines how the userâs account will appear in the âAccounts & Syncâ settings. Implementing an Account Authenticator requires 3 pieces: a service that returns a subclass of AbstractAccountAuthenticator from the onBind method, an activity to prompt the user to enter their credentials, and an xml file describing how your account should look when displayed to the user. Youâll also need to add the android.permission.AUTHENTICATE_ACCOUNTS permission to your AndroidManifest.xml.
The AccountManager
is good for the following reasons:
Accounts
, however, since you can easily manage that in your app without the need for this fancy-looking Accounts
thing⊠.Accounts
is to get rid of the traditional authorization with username and password each time an authorized feature is requested by the user, because the authentication takes place in the background and the user is asked for their password only in certain condition, which I will get to it later.Accounts
feature in android also removes the need for defining oneâs own account type. You have probably come across the apps using Google accounts for authorization, which saves the hassle of making a new account and remembering its credentials for the user.Accounts
can be added independently through Settings â AccountsAccounts
. For example, the client can access protected material at the same time in their android device and PC without the need for recurrent logins.Accounts
feature in android is to separate the two parties involved in any business dependent on Accounts
, so called authenticator and resource owner, without compromising the client (user)âs credentials. The terms may seem rather vague, but donât give up until you read the following paragraph ⊠đLet me elaborate on the latter with an example of a video streaming app. Company A is the holder of a video streaming business in contract with Company B to provide its certain members with premium streaming services. Company B employs a username and password method for recognizing its user. For Company A to recognize the premium members of B, one way would be to get the list of them from B and utilize similar username/password matching mechanism. This way, the authenticator and resource owner are the same (Company A). Apart from the users obligation to remember a second password, it is very likely that they set the same password as their Company Bâs profile for using the services from A. This is obviously not favorable.
To allay the above shortcomings, OAuth was introduced. As an open standard for authorization, in the example above, OAuth demands that the authorization be done by Company B (authenticator) by issuing some token called Access Token for the eligible users (third party) and then providing Company A (resource owner) with the token. So no token means no eligibility.
I have elaborated more on this and more on AccountManager
on my website here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With