This question is a bit old, but I think it is still of good interest.
AccountManager
, SyncAdapter
and ContentProvider
go together.
- You cannot have a
SyncAdapter
without anAccount
in theAccountManager
. - You cannot have a
SyncAdapter
without aContentProvider
.
But you can:
- use the
ContentProvider
without the others. - use the
AccountManager
without the others (but you cannot use anAccountManager
without aSyncAdapter
before Android 2.2 / Froyo API 8)
With AccountManager
/ SyncAdapter
/ ContentProvider
:
AccountManager
gives users a central point (Settings > Accounts) to define their credentials- Android decides when synchronization can be done via
SyncAdapter
. 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.TheContentProvider
schedules the database access in a background threadAsyncQueryHanlder
helps to query theContentProvider
in a background thread, preventing Application Not Responsive (ANR) errors while not requiring you to explicitly handle threading.ContentProvider
ties intoContentResolver
‘s observer: this means it is easy to notify views when content is changed
Bottom 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
- If you only want to store data, you should consider a simpler mechanism for data storage
- If you only need to fetch an only resource, you can use an
AsyncTaskLoader
- If you want to load images asynchronously, you can use specialized libraries like Square Picasso
- If you only want to execute some code at a given time, you can consider a Service / Alarm
- only available from API >= 7 (this doesn’t matter anymore)
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.