About the package name problem with AIDL client-server interaction-package

Source: Internet
Author: User
Tags getcolor

Today, when I was doing an example of aidl, I encountered a small problem, and two processes were unable to communicate. According to the example of the book (here the code from the Crazy Android Handout 2nd edition), or error, and finally on the Internet to find out the problem is the package name. In other words, the package name of the package in which the Aidl interface is defined must remain consistent with the client and server side. Otherwise it will error, the program forced to quit. The error message is as follows (things bind failed):

In debug mode, you will see the following exception (the target invocation exception) thrown:

This is because my package name is inconsistent, as follows:

The package is different, because it was the Icat.aidl file that was copied directly, the content is:

1 Package    com.qc.aidlservice;  2 Interface ICat 3 {4    String getColor (); 5     Double getweight (); 6 }

Because it involves the guide package, because the direct copy to the server will be error, so in the server file I need to import the package name changed to the following package:

1 Package    com.example.myaidlclientdemo;  2 Interface ICat 3 {4    String getColor (); 5     Double getweight (); 6 }

However, this will appear above the error, in fact, this superfluous caused a mistake. The simplest way to do this is to directly copy the package containing the Aidl file to our client after writing the server-side code. The system will automatically generate. java files for us, simple and convenient. As follows:

The last thing to note is that when configuring the service, you must not configure the service's properties to android:exported= "false", in this case:

1 <service android:name= ". Aidlservice "2             android:exported=" false ">3             <intent-filter >4                 < Action android:name= "Com.example.myaidldemo.action.AIDL_SERVICE"/>5             </intent-filter>6          </service>

This configuration of the external application of course no access AH (the reason for the mistake is to solve the IT warning problem is forgotten to change, so the program has been strong push, so be careful and careful again!!! )。

Should be configured to:

1 <service android:name= ". Aidlservice "2             android:process=": Remote >3             <intent-filter >4                 <action android:name= "Com.example.myaidldemo.action.AIDL_SERVICE"/>5             </intent-filter> 6         </service>

About the package name problem with AIDL client-server interaction-package

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.