Differences between the onstart () method and onstartcommand () method in Service

Source: Internet
Author: User

(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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.