I recently read about the GcmTaskService and GcmNetworkManager to schedule a task. My use-case is of typical SyncAdapter where I need to periodically sync some data with my server, and I currently use SyncAdapter. My question is what are the differences between GcmTaskService and SyncAdapter. And when to use GcmTaskService vs when to use SyncAdapter ?
GcmTaskService
: Implemented by the client application to provide an endpoint for the GcmNetworkManager
to call back to when a task is ready to be executed. Tasks must be scheduled based on an execution window in time. During this execution window the scheduler will use its discretion in picking an optimal execution time, based on network availability, network activity, and load.
Sync Adapter does the work of syncing the data between the server and the local database. Sync adapters run asynchronously, they transfer data regularly and efficiently, but not instantaneously. If you need to do real-time data transfer, you should do it in an AsyncTask or an IntentService. This framework helps manage and automate data transfers, and coordinates synchronization operations across different apps.
Google Cloud Messaging (GCM) provides both the server and device components you need to make this messaging system work. Using GCM to trigger transfers is more reliable and more efficient than polling servers for status. While polling requires a Service that is always active, GCM uses a BroadcastReceiver that's activated when a message arrives. While polling at regular intervals uses battery power even if no updates are available, GCM only sends messages when needed.