Search code examples
androidbroadcastreceiver

When should I use JobService in BroadCastReceiver.onReceive()?


I am reading the BroadcastReceiver.onReceive() documentation but I do not understand

If you need to perform any follow up background work, schedule a JobService with JobScheduler

I would be glad if someone could tell me what are the use-cases of such an approach.

Thank you in advance.


Solution

  • BroadcastReceiver may cause an ANR if the work inside onReceive takes a considerable amount of time. Because of that, you should consider moving long-running jobs to the worker, such as JobService, or using jetpack WorkManager.