(1): the difference between the onstart () method and the onstartcommand () method:
The onstart () method is used in versions earlier than android2.0. The onstartcommand () method is used in android2.0 and later versions. When they are used together, there is no conflict.
(2): When onstartcomand is used, an (INT) integer is returned.
This integer can return four values: start_sticky, start_no_sticky, start_redeliver_intent, and start_sticky_compatibility.
Their meanings are:
1): start_sticky: if the service process is killed, the Service State is retained to the starting state, but the intent object delivered is not retained. Then the system will try to re-create the service. Because the service status is starting, the onstartcommand (intent, Int, INT) method will be called after the service is created. If no startup command is passed to service during this period, the intent parameter is null.
2): start_not_sticky: "non-viscous ". When this return value is used, if the service is kill abnormally after onstartcommand is executed, the system will not automatically restart the service.
3): start_redeliver_intent: Re-transmits intent. When this return value is used, if the service is kill abnormally after onstartcommand is executed, the system automatically restarts the service and passes in the intent value.
4): start_sticky_compatibility: compatible version of start_sticky, but it is not guaranteed that the service will be restarted after it is killed.
(3) intentservice usage
When Android services are blocked, logoff and thread are used to solve the Logic Blocking problem in standard services. In Android, service and activity run in the same main thread. When the service program goes to sleep for 5 seconds, the activity also becomes a machine.
Intenservice is a subclass of service and is used to process asynchronous requests. The client passes the request to intentservice through the startservice (intent) method. intentservice processes each intent object through worker thread and stops the service after execution.
Intentservice requires two methods: One constructor and one onhandleintent () method.