AIDL (1), aidl

Source: Internet
Author: User

AIDL (1), aidl
AIDL (Android Interface Definition Language)

Description

Allows cross-process access between Android applications. Using AIDL technology means that other applications of the system can access the service components of their own applications. Android supports cross-process access in two ways: AIDL and Messenger. The difference between the two is that the former can process multiple threads, and the latter can only process single threads. Therefore, thread security must be ensured when AIDL is used.

Define remote service interfaces

1. Create the. aidl file (Create an AIDL file)

Create an AIDL file in the src directory of the project and define the interface in the file.

 



 

2. Implement the interface (Implementation interface)

Implement the AIDL interface in the service class

 

3. Expose the interface to clients (Expose the interface to the client)

 

Method for binding a remote interface object

1. Copy the AIDL interface file


2. Bind a remote service


3. Obtain the remote service interface object instance


4. Call the process Service Interface Method


Instance project download link http://download.csdn.net/detail/u010739551/7705575

For more information, see the AIDL (2) blog.




Android aidl allows two processes on different machines to communicate with each other (aidl does not seem to have ip or port attributes)

... No, buddy. You have to go through the Internet .. Two different machines must go through the network to interact. How can aidl... The network is connected to socket...

What is the difference between AIDL and Service?

The difference between the two lies in that local_servie does not need to write aidl files to implement the ipc Mechanism or bind through the ipc Mechanism because it is in different threads of the same process, the server only needs a new Binder.
Similar to this
Publicclass ServiceBinder extends Binder implements IService;
ServiceBinder serviceBinder = new ServiceBinder ();
Since remote service is not in the same process, you need to write an aidl file to implement ipc communication.
In addition, the binder object on the server is obtained through stub.
IService. Stub serviceBinder = new ICountService. Stub ()
The methods for accessing these two services are the same, except that exceptions must be caught when accessing remote servie.
In order not to write stub and other tedious ipc Mechanisms, android provides aidl. You only need to write aidl files, the compilation system will automatically generate the Code required to implement ipc for you.
As mentioned above, if you just want to create a service for yourself, then you will use the local service. If you get a common service in the system, that is, all program kinetic energy in the system accesses the service, you need to use remote service.
The concept of local service and thread is no longer at one level, and the positioning is also different. Some of the functions you implement with the local service can also be implemented using another thread. Different implementation methods naturally have advantages and disadvantages. This is determined by the characteristics of the thread and service. For example, the service only has one instance.
The local service does not have a ui. Therefore, it makes sense to run the local service statement in the main thread only when all the threads of the current process are finished and only the threads of the local service are left.
To complete a time-consuming task, you can start another thread or process, or start a local or remote service. There is no rule that the time-consuming task must start another thread.
The following section In sdk doc shows the difference between using service and using sub-threads.
Because a process running a service is ranked higher than one with background activities, an activity that initiates a long-running operation might do well to start a service for that operation, rather than simply spawn a thread-participates ularly if the operation
Will likely outlast the activity. examples of this are playing music in the background and uploading a picture taken by the camera to a web site. using a service guarantees that the operation will have at least service process priority, regardless of what
Happens to the activity. As noted in the Broadcast operator er lifecy ...... the remaining full text>

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.