Home » Android » What is the difference between GCMNetworkManager and JobScheduler in Android

What is the difference between GCMNetworkManager and JobScheduler in Android

Posted by: admin June 15, 2020 Leave a comment

Questions:

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

Can anyone help me for this.

How to&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.

Answer:

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