我不是以26为目标,但我想知道用户何时停用“后台活动”,如documentation中所述(以便在发生时显示通知)。
我有什么意思可以听吗?或以其他方式以编程方式知道它当前是否已被禁用?
答案 0 :(得分:0)
我设法找到一种方法来了解用户是否已停用了'后台活动'。 不确定它是最好的解决方案,但看起来它正在运行:
在我的粘性服务的onDestroy上,我安排了一份有时间限制的工作(带JobScheduler)。
当作业运行时,我检查我的粘性服务是否仍在销毁,而不是再次启动。 如果是这种情况,我会尝试从作业中启动服务,并检查是否成功:
ComponentName componentName = startService(serviceIntent);
if(componentName == null){
// we could not start the service, so user probably disabled the background activity
}