Service overview in Android

Source: Internet
Author: User

 

The main purpose of a Service is to provide backend service calls. Unlike an Activity, a Service has no interface. Because of this, it does not stop when a user leaves the application interface as an Activity, the Service is always running in the background unless the command is explicitly stopped.

 

Service also has a lifecycle. When the Service is started, the OnCreate () method is called first, and then the onStart () method is called. When the Service is stopped, the onDestroy () method is called.

 

You can call startService () or bindService () to start a Service (). When the former is used, the system will call the onCreate () method and onStart () method of the Service before the Service is started, and the Service does not stop after use, unless you explicitly stop using stopService. BindService () is used to bind a Service. If the Service does not exist, the binding fails. However, you can set the bindService () parameter to enable the Service when the Service does not exist, after a Service is started using this method, the system automatically stops the Service.

 

If you only provide background services, you can use Thread threads without using services. Service also features inter-process Service calls, which can be called not only within an application, but also across applications. The program that calls the Service becomes the Client.

 

To prevent Client threads from being suspended, generally, when a Service is created, a Thread is re-created to complete the specific work. The Service only provides a called interface. If the Client is in another program, the Client and Service run in different processes.

 

From Yanyun's column

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.