Reputation: 2129
I have a hobby application (Alarm Clock) in which I have lots of short-lived services. All of these services are kicked-off by a BroadcastReceiver
when internal intents are broadcast. Many of these services react on the same intents, for example, when an alarm fires, VibrationService
, KlaxonService
and FlashLightService
are all started. There are some other Services and receivers which do small amounts of work as well. In the past, everything was fine. Lately, the number of services increased and I have started to notice considerable lag when a "popular" intent is broadcast.
All of my services are not exported and run on the main thread.
Now my question is, how expensive is creation/destruction of a service? Does it make sense to use one "HostService" and do all the work there (in my case it will replace 4-5 services)?
Upvotes: 2
Views: 312
Reputation: 10193
The tidiest way to create short-lived services is to use IntentService instead of fully fledged services. These run on their own thread and terminate once they have handled all queued intents.
Judging by the names of your services you should also look at notification manager. This can pro most of your workload without the need for separate services.
Upvotes: 2