Caused by: java.lang.IllegalStateException: Not allowed to start service Intent

Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=package/xxx.xxxService }: app is in background uid UidRecord


Android 8.0(+)不允许在后台启动/创建Service,直接调用context.startService(intent)会宕机。

临时解决办法:

将编译版本和目标版本降级到25,就可以避免因为8.0(26)不允许APP在后台启动Service而宕机。因为系统版本向后兼容。

根本解决办法:
1、SDK26 启动Service的方法:context.startForegroundService(context, Service.class);
2、SDK26 Service启动时,即在onCreate方法中,context.startForeground(id, new Notification());

你可能感兴趣的:(Android)