Aidl简单使用例子
AIDL是Android中IPC(Inter-Process Communication)方式中的一种,AIDL是Android Interface definition language的缩写,对于小白来说,AIDL的作用是让你可以在自己的APP里绑定一个其他APP的service,这样你的APP可以和其他APP交互。
打开AndroidStudio创建两个module,例如 aidlClient aidlServer
1.aidl接口文件
// IBook.aidl
package com.example.androidbinddemo;
// Declare any non-default types here with import statements
interface IBook {
/**
* Demonstrates some basic types that you can use as parameters
* and return values in AIDL.
*/
void borrowBook(String number, int count);
}
2.创建一个服务例如 BookService
class BookService : Service() {
private var handler = Handler(Looper.getMainLooper()