Search code examples
androidservicesingletonbackground-service

Avoid Multiple Instances for a Service


I have created a foreground service, which is working perfectly and performs tasks in the background, But whenever I call startForegroundService onCreate method is getting called.

As I know and according to documentation, Service is a kind of singleton class but still, multiple instances are getting created.

Does anyone have any idea How can I avoid multiple instances of service??


Solution

  • Service was getting destroyed but the handler whose instance was getting created repeatedly here. Issue solved by removing handler in onDestroy of Service @greeble31 Thanks for your hint