当应用程序被用户杀死时,工作管理器不工作.为什么?
问题描述:
我想执行一项任务,即使在使用工作管理器终止应用程序之后也是如此.但是,应用程序被杀死后,任务不会执行.
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);
答
据我所知,工作经理取决于设备制造商.就我而言,它是一个 miui 设备,它不允许工作管理器在应用程序被终止或重新启动的情况下工作.当我为应用程序提供自动启动权限"时,工作经理开始工作.
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".