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?
Services like Activities are started through use of the
Intentsystem. You can start a service using thestartService(intent);method. This crosses application boundaries as long as the service is properly configured to answer intents from outside of it’s own sandbox.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.
Services have access to the application context (and therefore can post
Toasts or startActivitiesof 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 howeverServicesare not designed to interface with the UI even though it’s possible.Services can be started with different flags (and can be programmed differently) to allow them to service received
Intentsin an asynchronous way or to queue theIntentsto be performed serially. You can find more about this (and the rest of your question here)Plugins?
You can install a service as a seperate app which can catch
startService()calls it’s making if it isn’t using a namedIntent. This service would be in a different sandbox however and wouldn’t have access to the running app’s variables/state.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 theActivity).