Chapter 28 Background Services
Sync adapters also integrate nicely with the OS from a user perspective. You can expose your app
as a sync-able account that the user can manage through the Settings → Accounts menu. This is
where users manage accounts for other apps that use sync adapters, such as Google’s suite of apps
(Figure 28.2).
Figure 28.2 Accounts settings
While using a sync adapter makes correct usage of scheduling repeating network work easier – and
allows you to get rid of the alarm management and pending intent code – a sync adapter does require
a bunch more code. First, a sync adapter does not do any of your web requests for you, so you still
have to write that code (e.g., FlickrFetchr). Second, it requires a content provider implementation to
wrap the data, account, and authenticator classes to represent an account on a remote server (even if the
server does not require authentication), as well as a sync adapter and sync service implementation. It
also requires working knowledge of bound services.
So if your application already uses a ContentProvider for its data layer and requires account
authentication, using a sync adapter is a good option for you to consider. It is a big advantage that sync
adapters integrate with the UI provided by the OS, too. JobScheduler does not do that. If none of those
considerations apply, the extra code required might not be worth it.
The online developer docs provide a tutorial on using sync adapters at developer.android.com/
training/sync-adapters/index.html. Check it out to learn more.