I have been trying to migrate from Firebase Job Dispatcher to androidx Work Manager. My app was working well with Job Dispatcher. The problem with Work Manager is that it doesn't execute the Periodic Work after the app is closed. Without Periodic Work running, users cannot receive notifications.
My app is being tested on several Pixel Emulators (e.g. SDK Level 30) launching from Android Studio. I expected stock Android behavior from those emulators. I also tested by using physical phones and got the same problem.
I have been searching for the solution but so far without luck. Could you help identifying the cause and the solution?
Here is my Java code:
Constraints constraints = new Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build();
PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest.Builder(MyClass.class, 15, TimeUnit.MINUTES)
.addTag("my_tag")
.setConstraints(constraints)
.setInitialDelay(15, TimeUnit.MINUTES)
.build();
WorkManager.getInstance(appContext)
.enqueueUniquePeriodicWork("my_unique_work_name", ExistingPeriodicWorkPolicy.REPLACE, periodicWorkRequest);
Log.d ( "From Work scheduling procedure...", "periodicWorkRequest enqueued" );
Here is my configuration in build.gradle (app level)
implementation 'androidx.work:work-runtime:2.4.0'