Context.startForegroundService()然后未在BroadcastReceiver中调用Service.startForeground() [英] Context.startForegroundService() did not then call Service.startForeground() In BroadcastReceiver
本文介绍了Context.startForegroundService()然后未在BroadcastReceiver中调用Service.startForeground()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要您的帮助来解决此问题:
I need your help to resolve this problem :
Context.startForegroundService() did not then call Service.startForeground()
我正在使用 BroadcastReceiver 来启动通知服务:
I'm using a BroadcastReceiver to start the notification service :
@Override
public void onReceive(Context context, Intent intent) {
WakeLock.acquire(context);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ContextCompat.startForegroundService(context, new Intent(context, StartNotificationService.class).putExtras(intent));
} else {
context.startService(new Intent(context, StartNotificationService.class).putExtras(intent));
}
}
请问您有什么想法吗?我该如何解决这个问题? 谢谢你
Have you any idea please ? How can I resolve this issue ? Thanks you
推荐答案
您的Service
在启动时必须调用startForeground()
,否则系统将不允许它运行.
Your Service
must call startForeground()
when it is started, otherwise the system will not allow it to run.
这篇关于Context.startForegroundService()然后未在BroadcastReceiver中调用Service.startForeground()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文