我正在使用ListenableWorker执行后台任务。 同时,我希望操作系统知道我的服务的重要性,因此我调用
setForegroundAsync(new ForegroundInfo(WorkerConstants.NOTIFICATION_FOREGROUND_ID,
builder.build()));
正如谷歌文档所建议的那样。
但是,当我的服务停止或取消时,我仍然可以看到前台服务通知,并且我无法将其删除。
此外,我向这个通知添加了取消按钮,但它没有任何作用,我无法关闭它:
PendingIntent intent = WorkManager.getInstance(getApplicationContext())
.createCancelPendingIntent(getId());
builder.addAction(R.drawable.ic_redesign_exit,"Stop",intent);
有什么建议吗?