Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between GCMNetworkManager and JobScheduler in Android

Tags:

android

Hi I could not find any thread on stackoverflow regarding difference between GCMNetworkManager and JobScheduler in Android.

Can anyone help me for this.

like image 435
N Sharma Avatar asked Sep 24 '16 08:09

N Sharma


People also ask

What is the difference between WorkManager and JobScheduler in Android?

As mentioned in the previous section, WorkManager internally uses the JobScheduler API on Android 6.0 (API Level 23 – Marshmallow) and above devices. Therefore, there won't be any major differences between the WorkManager and JobScheduler on Android 6.0 and above devices. Both would behave in the same way.

What is JobScheduler in Android?

android.app.job.JobScheduler. This is an API for scheduling various types of jobs against the framework that will be executed in your application's own process. See JobInfo for more description of the types of jobs that can be run and how to construct them.

When would you use a WorkManager?

Use WorkManager for reliable workWorkManager is intended for work that is required to run reliably even if the user navigates off a screen, the app exits, or the device restarts. For example: Sending logs or analytics to backend services. Periodically syncing application data with a server.

What is the best tool for handling work that is deferrable?

- [Narrator] Android's WorkManager architecture is designed to handle deferrable, long-running tasks. When you set up a task, it's guaranteed to run whenever the constraints you defined are satisfied.


2 Answers

Both do the same thing, the difference is when you can use or the other.

  • JobScheduler was introduced on API 21 as part of the Android framework. If your app minimum API level is 21, you should use this one.

  • GCMNetworkManager is a "compat" version of it that is proocessed/executed via Google Play Services (so it works on device). If your app minimum API level is less than 21, you should use this one.

Also important to note, is that GCMNetworkManager have been replaced by FireBase JobDispatcher (https://github.com/firebase/firebase-jobdispatcher-android), so you shouldn't use GCMNetworkManager anymore and use this one instead.

like image 131
Budius Avatar answered Oct 22 '22 12:10

Budius


The single solution for scheduling background work is now WorkManager: https://developer.android.com/topic/libraries/architecture/workmanager

Under the hood, WorkManager detects what API level your app is running on and uses JobScheduler (for API 23+) or AlarmManager + BroadcastReceiver (for API 14-22).

Uses JobScheduler for API 23+ Uses a custom AlarmManager + BroadcastReceiver implementation for API 14-22

like image 29
Caren Avatar answered Oct 22 '22 14:10

Caren