Android 8.0之后Service使用问题
背景:
原因
遇到的问题
android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground()1. 添加权限
<!--android 9.0上使用前台服务,需要添加权限,此权限为级别为nomarl-->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />2. 启动server(引用启动5秒内要启动server)
3. Server中onCreate方法中调用startForeground()
4. 在onStart里再次调用startForeground()
注解:
Last updated
Was this helpful?