开发者

How do I stop multiple services from taking one intents instructions?

We have 2 applications that both have identical services to pull messages from a webservice. To save battery power we only need 1 service to do the pulling for both applications, but in case of a uninstall of application1 we need application2's service to take over the pulling.

We are acheiving this by sending an implici开发者_开发百科t intent to see if any of OUR other apps can start up and take over.

However: If i try just to stop the service, without uninstalling the whole application, it seems that both our applications respond with starting their services (suddenly we go from 1 service to 0 to 2).

**Edited by request since the question was cryptic, some of the answers/comments below will be to the previous question, sorry for the fuss folks!


There are ways of checking to see if certain apps are installed and (I believe) ways to discover what things are currently running. I'm not aware, however, of any way to provide conditional information in an Intent to say things like 'use this service instance if available' (for example).

My approach would be to create a third app which does nothing but contain an IntentService (i.e., it has no Activities, therefore no UI). I'd then remove the service code from both of the other apps and just have them use the single instance of the IntentService which lies dormant when it has nothing to do.

As the service is specific to your own apps, I'd probably avoid using an implicit Intent (i.e., specifying action/category) and instead use an Intent which explicitly specifies the service class itself. IntentService can be created/started with either startService() or bindService() either or both may be applicable depending on your applications' requirements.


Usually there is a popup asking which app should consume the intent. And the intent is then routed to that app. You can also mark one app as default there.

Perhaps you need to 'reset' this chooser?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜