Android programming:pushing The Limits--Chapter 7:android IPC--APIWrapper

Source: Internet
Author: User

The previous two pieces of article explain the Android IPC through Aidl and Messenger two ways. This article is not about the third IPC, but the first two ways to encapsulate, so that we do not have to directly copy the Aidl file, Java files to the client, but to provide the client with an AAR (anroid Archive) package. By encapsulating the Aidl or messenger through this AAR package, the client can end up calling the generic Java class without having to deal with the communication content. (In fact, it was said to be packaged as a jar package, but in the new Java Library module, I failed to create the Aidl file successfully, and finally I chose AAR.) How to create an AAR please read: Building an AAR Library in Android Studio).

This article does not explain the code, if not clear, please read first:

Android programming:pushing The Limits--Chapter 7:android IPC--Aidl

Android programming:pushing The Limits--Chapter 7:android IPC--Messenger

The sample code for this article:

Service:https://github.com/ldb-github/wrappedaidlservice

Client:https://github.com/ldb-github/wrappedaidlclient

Service side:

The project consists of two module:

The app module is where the service resides.

The Wrappedaidl module is an Android Library that eventually generates an AAR package that is provided to the client. This module actually encapsulates the code that originally communicates with the server in the client.

This project contains two ways of Aidl and Messenger. which

APIWrapper is the encapsulation of the Aidl way.

Apiwrapperbymessenger is the encapsulation of Messenger mode.

In order to be able to callback the client, add a callback interface Apicallback,apiwrapper or Apiwrapperbymessenger will call the appropriate callback method at different times of the communication to pass the message to the client.

Client:

This allows the client to add the AAR package instead of directly copying the server's files:

You also have to modify the module's Build.gradle file:

This allows apicallback,apiwrapper and apiwrapperbymessenger to be used on the client.

Client UI:

Android programming:pushing The Limits--Chapter 7:android IPC--APIWrapper

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.