I want to sync with the server every time the user connects to the internet. So far I have been using WorkManager to do the job with 3-hour intervals and constraints requiring internet-connected. But it is missing the intervals where the device is connected to the internet but the work period is not reached. I want it to run every single time the user connected to the internet.
Below is the sample code I am using:
val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
val work = PeriodicWorkRequestBuilder<ExampleWorker>(3, TimeUnit.HOURS)
.setConstraints(constraints)
.build()
val workManager = WorkManager.getInstance(context)
workManager.enqueueUniquePeriodicWork(UniqueWorkerTag,
ExistingPeriodicWorkPolicy.KEEP, work)
I have gone through different pages and the only solution I find is to use Firebase JobScheduler but it is now deprecated.