1

I am designing a service that can be used by more than 1 applications. The service currently use accelerometer with some calculation and use sendBroadcast() to send some value to applications that use it.

I've tried to share the code among applications.The result is that when an application calls startService(), an instance of service is created, but when another application calls startService(), another instance of service is created without knowing that the service is already created.

How can I can implement a system such that when no application is running, the (first) application invoke the service. The other (lately started) applications send invocation signal to the service, but nothing happens (because the service has already been started)?

user2864740
  • 60,010
  • 15
  • 145
  • 220
nut3z
  • 11
  • 2
  • you may find answer from [here](http://stackoverflow.com/questions/6204492/android-shared-service) – calvinfly Jun 30 '15 at 03:30
  • @calvinfly Thanks for the link. The solution with and PackageManager is interesting, but I'm quite new to this and haven't used this before. Is giving an example for this possible? – nut3z Jun 30 '15 at 04:05
  • @calvinfly Used ActivityManager from [this](http://stackoverflow.com/questions/600207/how-to-check-if-a-service-is-running-on-android) and it works! Thanks again for your effort. – nut3z Jun 30 '15 at 04:36
  • good to see you do it:) – calvinfly Jun 30 '15 at 04:54
  • Your question makes no sense. Android will not start more than 1 instance of a specific `Service`. Please post the code you are using to start the `Service` and the manifest entry for the `Service`. – David Wasser Jul 01 '15 at 15:41

0 Answers0