避免一个服务的多个实例

Avoid Multiple Instances for a Service

我创建了一个前台服务,它运行良好并在后台执行任务, 但是每当我调用 startForegroundService onCreate 方法时都会被调用。

据我所知,根据 documentation,服务是一种单例 class,但仍然会创建多个实例。

有谁知道如何避免多个服务实例?

服务正在被销毁,但其实例的处理程序在这里被重复创建。 通过删除 onDestroy of Service 中的处理程序解决了问题 @greeble31 感谢您的提示