I want to know some basic, practical, things about Services, that are not explicitly mentioned in the Android Developers reference pages.
How can I call a service from another app, that has not even started?
How do I query which services are provided by other applications?
Are services allowed to use UI methods? (the documentation says they are specifically meant not to have UI to the user, but their example has a Toast in it)
Are services re-entrant? (if two apps call the same service, will they be 'serviced' at the same time without messing with any local variable)
Are services the way plug-ins are made?
Can I use a service to extend the functionality of my already installed app? (i.e. can I 'install' just a service
- Can services launch normal activities? Can they cause their clients to finish?
How can I call a service from another app, that has not even started?
Services like Activities are started through use of the Intent
system. You can start a service using the startService(intent);
method. This crosses application boundaries as long as the service is properly configured to answer intents from outside of it's own sandbox.
How do I query which services are provided by other applications?
Documentation. I can't imagine a situation where you would want to interrogate an app for it's services without the documentation as you wouldn't know what to pass in order to get the service to perform correctly.
Are services allowed to use UI methods? (the documentation says they are specifically meant not to have UI to the user, but their example has a Toast in it)
Services have access to the application context (and therefore can post Toast
s or start Activities
of their own). They may also have visibility of the app running in the same sandbox, this means that by means of handlers they can change the UI of the running Activity directly. By their nature however Services
are not designed to interface with the UI even though it's possible.
Are services re-entrant? (if two apps call the same service, will they be 'serviced' at the same time without messing with any local variable)
Services can be started with different flags (and can be programmed differently) to allow them to service received Intents
in an asynchronous way or to queue the Intents
to be performed serially. You can find more about this (and the rest of your question here)
Are services the way plug-ins are made?
Plugins?
Can I use a service to extend the functionality of my already installed app? (i.e. can I 'install' just a service
You can install a service as a seperate app which can catch startService()
calls it's making if it isn't using a named Intent
. This service would be in a different sandbox however and wouldn't have access to the running app's variables/state.
Can services launch normal activities? Can they cause their clients to finish?
Yes, if the Service is running in the same sandbox they can have visibility of the App running alongside it. It can use startActivity()
as it has access to application context and it can call static methods inside of the app (which could contain static access to the Activity
).