Android 8.0: java.lang.IllegalStateException: Not allowed to start service Intent

前端 未结 17 1234
借酒劲吻你
借酒劲吻你 2020-11-22 09:15

On application launch, app starts the service that should to do some network task. After targeting API level 26, my application fails to start service on Android 8.0 on back

17条回答
  •  深忆病人
    2020-11-22 09:45

    Yeah, that's because you can't start services in the background anymore on API 26. So you can start ForegroundService above API 26.

    You'll have to use

    ContextCompat.startForegroundService(...)
    

    and post a notification while processing the leak.

提交回复
热议问题