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.