You can pass an intent object (specify the service to be started) to the startservice () method to start the service from an activity or other application component. The Android system calls the onstartcommand () method of the service and passes the intent object to it (you should not directly call the onstartcommand () method)
For example, an activity can use the startservice () method with a clear intent object to start a service:
Intent intent = new intent (this, helloservice. Class );
Startservice (intent );
The startservice () method returns immediately, and the Android system calls the onstartcommand () method of the service. If the service is not running, the system first calls the oncreate () method and then calls the onstartcommand () method.
If the service does not support binding, the intent object sent by the permanent startservice () method is the only communication mode between the application component and the service. However, if you want the service to send a feedback, the client that starts the service can create a pendingintent object for broadcasting (using the getbroadcast () method ), and send it to the service where the intent object of the startup service is located. Then the service can use this broadcast object to send results.
The results of starting multiple services are in the onstartcommand () method of calling the service, but as long as one request terminates the Service (using the stopself () method or stopservice () method), the service needs to be terminated.