androidlocationintentserviceandroid-workmanagerjobintentservice

Best way get GPS Location in background for Android API level 30 and higher


My application determines the speed limit by the user's location and tells the user if he has exceeded it. Starting with Android API level 30 and higher, Google has defined IntentService as deprecated and suggests using WorkManager or JobIntentService and also states that it is necessary to migrate from Firebase JobDispatcher to WorkManager. I see two ways to solve this problem:

  1. Start OneTimeWorkRequest and specify to restart this method periodically in this method while the application is running in the background.
  2. Run PeriodicWorkRequest with a minimum allowed interval of 15 minutes. In this method, run the JobIntentService method, which runs for up to about 10 minutes, but the method may not run or may be destroyed by the system before it is complete.

I'm worried about:


Solution

  • I would prefer going with second option, it gives you more time between each rescheduling of the Worker.

    Regarding your concerns: