当应用程序被用户杀死时,工作管理器不工作.为什么? [英] Work Manager not working when app is killed by the user. Why?

查看:26
本文介绍了当应用程序被用户杀死时,工作管理器不工作.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行一项任务,即使在使用工作管理器终止应用程序之后也是如此.但是,应用程序被杀死后,任务不会执行.

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".

这篇关于当应用程序被用户杀死时,工作管理器不工作.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆