Context.startForegroundService() did not then call Service.startForeground() In BroadcastReceiver

倾然丶 夕夏残阳落幕 提交于 2019-12-11 16:05:57

问题


I need your help to resolve this problem :

Context.startForegroundService() did not then call Service.startForeground()

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


回答1:


Your Service must call startForeground() when it is started, otherwise the system will not allow it to run.



来源:https://stackoverflow.com/questions/56043351/context-startforegroundservice-did-not-then-call-service-startforeground-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!