小编Chi*_*ati的帖子

在android版本8.0中,我使用工作管理器定期触发广播,但是当我从最近的任务中清除应用程序时,它不起作用

我已安排工作经理定期在特定时间执行任务。但它正在与其他Android版本一起使用,例如25或更低版本。当我在API 28上运行它时,如果我从最近的列表中清除应用程序,它将停止触发广播。

我在活动中安排了这样的工作经理:

 OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(MyWorker.class).setInitialDelay(15, TimeUnit.SECONDS).build();
 WorkManager.getInstance().enqueue(mywork);
Run Code Online (Sandbox Code Playgroud)

这是我的工人班:

public class MyWorker extends Worker {
    @NonNull
    @Override
    public Worker.WorkerResult doWork() {
        // Do the work here
        Mylogger.getInstance().printLog("MyWorr","doWork()");
        //fire broadcast from here
        Intent broadcastIntent = new Intent(getApplicationContext(), TimeMatchingBroadcastReceiver.class);
        getApplicationContext().sendBroadcast(broadcastIntent);
        CommonUtils.scheduleWorkManager();
        // Indicate success or failure with your return value:
        return WorkerResult.SUCCESS;

        // (Returning RETRY tells WorkManager to try this task again
        // later; FAILURE says not to try again.)
    }
}
Run Code Online (Sandbox Code Playgroud)

即使关闭或清除所有版本的android上的最新应用程序,我也要执行工作管理器。谢谢。

android android-service android-lifecycle android-jetpack android-workmanager

1
推荐指数
1
解决办法
1262
查看次数