小编Sah*_*hta的帖子

startService()抛出java.lang.IllegalStateException

onCreate()我的活动,

我试图通过以下代码启动服务:

Intent intent = new Intent();
intent.setClassName(SERVICE_PKG_NAME, SERVICE_NAME);
context.startService(intent); //context = MainActivity.this
Run Code Online (Sandbox Code Playgroud)

但是,我收到以下异常:

java.lang.IllegalStateException:不允许启动服务Intent(service-name):app在后台

知道这可能是什么原因吗?现在坚持几个小时.

android android-service android-8.0-oreo

7
推荐指数
1
解决办法
4507
查看次数