Work Manager not working when app is killed by the user. Why?

kapsid picture kapsid · Mar 26, 2019 · Viewed 7k times · Source

I want to execute a task, even after the application is killed using work manager. But, the task is not executed after the app is killed.

    workManager = WorkManager.getInstance();
    Constraints constraints = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build();
    OneTimeWorkRequest saveData = new OneTimeWorkRequest.Builder(SaveDataWorker.class).setConstraints(constraints).setInitialDelay(10,TimeUnit.SECONDS).build();
    workManager.enqueue(saveData);

Answer

kapsid picture kapsid · Mar 27, 2019

As I found out, the work manager depends on the device manufacturer. In my case, it is an miui device, which does not allow work manager to work in case the app is killed or rebooted. The work manager worked when I provided the application with "autostart permission".