- InterfaceLoader是一款Android跨进程接口调用框架,可以替代Android AIDL
- 史上最好用的Android跨进程接口调用框架
- 因为不想用AIDL!
- 因为不想用AIDL!!
- 因为不想用AIDL!!!
- 基于AIDL的跨进程通信是一种典型的代理模式,由.aidl文件生成client端的proxy和server端的binder,但是我觉得生成的代码总觉得看起来很别扭,也很难用。
- 所以InterfaceLoader使用动态代理代替了AIDl的代码生成,非常巧妙。不仅减少了生成的代码,也让跨进程通信的使用体验更接近普通的接口调用,这就是InterfaceLoader的奇妙之处。
Via Gradle:
implementation 'com.jeremyliao:interface-loader:0.0.1'
- 例如:
public interface ILoaderDemo {
int plus(int a, int b);
int minus(int a, int b);
int multi(int a, int b);
}
- 定义Android Service
- 在onBind方法中调用InterfaceService.newService:
InterfaceService.newService(ILoaderDemo.class, new ILoaderDemo()
- 定义Activity
- 通过bindService获取IBinder
- 通过InterfaceLoader.getService调用接口的方法
InterfaceLoader.getService(ILoaderDemo.class, binder)
.plus(10, 20);