An explanation of the Android service classification

Source: Internet
Author: User

Classification by starting mode

  Google's official website Classification of Service

  The Service is divided into two categories depending on how it is started:Started and Bound. whereStarted () is started by StartService () and is used primarily for service within the program , while Bound is started by Bindservice () , allowing multiple applications to share the same Service .

  Started Service

  1.startService () to start

  StartService through the contact of the Activity

Call startservice (service).

  2, once started, runs in the background, even if the object that started it (Activity) is destroyed

  3, usually only started, does not return a value

  4, usually network upload or download, after the operation is completed, automatically stop

  Onstartcommand ()

  Onstartcommand Service inside the method

  Bound Service

  1,bindservice () to bind

will call Bindservice to bind

  2, provide client server interface to start

It has a model of client and server segments

  3, send the request, get the return value, even through the IPC to communicate

  IPC internal process communication to communicate.

  4, a service can be bound by multiple callers, as long as there is a binder, the service runs, all the bindings are exited, the service exits

I am also now a service, and I may use Activity a binds to it,b binds him, and when I exit a , because b is bound, So the service will not quit yet.

It is when all the bindings have exited that our service will quit.

  Onbind ()

He's going to use an overloaded method called Onbind.

According to the nature of service

  Local Service 

Local service, which refers to the same process for internal application

Features: Some time-consuming tasks for implementing the application itself, such as querying for upgrade information and not consuming applications such as Activity belongs to the thread, but a single thread in the background execution, so the user experience is better.

use: In The Service can call context.startservice () to start and call Context.stopservice () to end. Internally you can call service.stopself () or service.stopselfresult () to stop yourself. No matter how many times StartService ()is called, only one StopService () is called to stop.

  Remote Service  

remote services, which are remote in Android, refer to the server-side client model that is used between different processes, for applications within the Android system.

Features: Can be reused by other applications, such as the weather Service, other applications do not need to write such services, call the existing can.

use: You can define an interface and expose the interface for other applications to operate. The client establishes a connection to the service object and invokes the service through that connection. Call the Context.bindservice () method to establish a connection and start to call Context.unbindservice () to close the connection. Multiple clients can bind to the same service. If the service is not loaded at this time,bindservice () loads it first.

Classification by Implementation method

  Java Service

  Native Service

Native Service is the system-level service we use in C and C + +, we can think of it as the inner layer of the library .

  Native Service, this isAndroida feature of the system is theC + +orCThe code is written out forJavafor a remote call.Remote Service, becauseC + +The code generates aNativeCode (machine code), so callNative Service. WithAndroidthe performance needs of the system are getting higher,Native Servicedemand will increase.

in the Service inside to use it, there is no need to manifest inside the configuration, with the configuration will know,manifest All the elements are classes, so we must have a The class of the Service.

The configuration of the Service is simple, just configure its name.

original link:http://www.maiziedu.com/wiki/component/classify/

An explanation of the Android service classification

Related Article

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.