在检查了谷歌问题和很多其他问题之后,我找到了我在底部添加的解决方案。
我所关心的事情如下:
onCreateAND 中onStartCommand,我确保将服务移至前台(如果它尚未位于前台)onStartCommand处理程序的额外命令来执行此操作,以确保服务在启动时不会停止(最终在它完成进入前台之前)context.stopService(...)),我总是通过正在运行的服务本身的命令来停止服务 - 所以我确保它只能在它在前台运行时停止,而不是在启动期间停止我个人使用该服务进行覆盖,因此我不在类中处理活页夹,因为我不使用它们。
我得到的日志
2019-07-29 21:41:27,146 [[BaseOverlayService:62 onCreate]]: onCreate
2019-07-29 21:41:27,146 [[BaseOverlayService:142 b]]: BEFORE moveToForeground (called by onCreate)
2019-07-29 21:41:27,152 [[BaseOverlayService:159 b]]: AFTER moveToForeground (called by onCreate) - moved to foreground: true
2019-07-29 21:41:27,176 [[BaseOverlayService:79 onStartCommand]]: onStartCommand: isForeground: true | action: null | isStopping: false
2019-07-29 21:41:27,945 [[BaseOverlayService:142 b]]: BEFORE moveToForeground (called by updateNotification [OverlayService [onInitFinished]])
2019-07-29 21:41:27,947 [[BaseOverlayService:159 b]]: AFTER moveToForeground (called …Run Code Online (Sandbox Code Playgroud)