Android Aidl and normal service

Source: Internet
Author: User

Recently saw the doctor's "Android Art development exploration" feel very fruitful. So also want to record a blog, because blogging is really the accumulation and summary of the process. All right, no more talking nonsense.

Service is divided into 2 kinds, one is the ordinary service, is directly inherit the service class, relatively simple. The main thing to note is that this class runs on the main thread and cannot do time-consuming work. If you need to do time-consuming work, I need to open another thread.

Based on the official documentation of the service's basic method of interpretation:

Onstartcommand (): When other components call the StartService () method, this method is called once and runs in the background. If you implement a method, you need to call stopself or StopService after this method is completed (if you just want to get the binding you don't have to implement this method). This is also the basic service to work on the method, the function you want to implement here. One thing to note is that this method is not invoked when you open the service through Bindservice

The Onstartcommand callback method also has a return value, which gives the system a total of 3:

1, Start_not_sticky the value of the document says that the system will not easily kill the service before you complete the work. is a relatively safe value. The system will not re-create this service

2, Start_sticky When we return this value, we re-create the service, but we will not pass the intent object again. This is more suitable for multimedia playback


Onbind (): When other components want to bind to the service (for example, to implement a remote protocol call RPC), in this method implementation you must provide the IBinder interface to communicate with the client. Methods that must be implemented to implement cross-process communication

onCreate (): When the service is first created, the system callback, you can do some initialization work here

OnDestroy (): When the service is destroyed, the system callback, do some free memory operation

There is also a function that can also implement the service, that is Intentservice, this and the above is the difference is that we have to operate in the onhandleintent. And this callback is time-consuming to work with.


The following is the start service, start the service mainly two ways, the first is StartService, when we start a implementation of the Onstartcommand service, OnCreate after the call, and start again will not call the method.






This article is from the "first entry Hermitage" blog, please make sure to keep this source http://wangjinxue.blog.51cto.com/3819301/1714734

Android Aidl and normal service

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.