当前位置:网站首页>AIDL detailed explanation
AIDL detailed explanation
2022-08-05 05:38:00 【suiyue010211】
目录
If you now want to do interprocess communication,应该如何操作?
AIDL是什么?
Android Communication interface definition language
AIDL用在哪?
两个app进程间通信
If you now want to do interprocess communication,应该如何操作?
分为客户端和服务端
What should the server do?
1. 定义.aidl文件,An abstract method that defines a concrete business
interface ServiceAidlInterface {
void setname(String name);
void setmoney(int money);
String getinfo();
/**
* Demonstrates some basic types that you can use as parameters
* and return values in AIDL.
*/
void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
double aDouble, String aString);
}
2. 将项目rebuild,The system will automatically generate and.aidl文件同名的java文件
3. 创建新的类,让类继承 接口.Stub
public class SericeImpl extends ServiceAidlInterface.Stub{
private String name;
private int money;
@Override
public void setname(String name) throws RemoteException {
this.name=name;
}
@Override
public void setmoney(int money) throws RemoteException {
this.money=money;
}
@Override
public String getinfo() throws RemoteException {
Intent intent=new Intent();
intent.setClass(MyService.this,MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("name",name);
intent.putExtra("money",money);
startActivity(intent);
return "你的名字是"+name+"花了"+money+"块";
}
@Override
public void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString) throws RemoteException {
}
}4. 向客户端公开接口,rely on service
public class MyService extends Service {
public MyService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
return new SericeImpl();
}what the client does?
1. 将服务器的.aidlPut the package into the client together,将项目rebuild
2. in the process of binding the service,Unable to connect to the interface exposed by the server(API 30)
<queries>
<package android:name="com.wzk.serviceapptoo"/>
</queries>3. 在Activity中绑定服务
Intent intent=new Intent();
intent.setComponent(new ComponentName("com.wzk.serviceapptoo","com.wzk.serviceapptoo.MyService"));4.绑定服务后,Start a conversation with the server
bindService(intent,conn,BIND_AUTO_CREATE);
try {
serviceAidlInterface.setname("小小");
serviceAidlInterface.setmoney(5000);
String getinfo = serviceAidlInterface.getinfo();
Log.i("服务", "onClick: "+getinfo);
} catch (RemoteException e) {
e.printStackTrace();
}边栏推荐
- CVPR 2022 |节省70%的显存,训练速度提高2倍
- 大型Web网站高并发架构方案
- Flutter 3.0升级内容,该如何与小程序结合
- 学习总结week2_2
- [Pytorch study notes] 9. How to evaluate the classification results of the classifier - using confusion matrix, F1-score, ROC curve, PR curve, etc. (taking Softmax binary classification as an example)
- 【数据库和SQL学习笔记】9.(T-SQL语言)定义变量、高级查询、流程控制(条件、循环等)
- 盘点关于发顶会顶刊论文,你需要知道写作上的这些事情!
- 【Pytorch学习笔记】8.训练类别不均衡数据时,如何使用WeightedRandomSampler(权重采样器)
- [Redis] Resid的删除策略
- 【NFT网站】教你制作开发NFT预售网站官网Mint作品
猜你喜欢

el-pagination左右箭头替换成文字上一页和下一页

【数据库和SQL学习笔记】3.数据操纵语言(DML)、SELECT查询初阶用法

盘点关于发顶会顶刊论文,你需要知道写作上的这些事情!

The fourth back propagation back propagation

MaskDistill-不需要标注数据的语义分割

怎么更改el-table-column的边框线

神经网络也能像人类利用外围视觉一样观察图像

flink部署操作-flink on yarn集群安装部署

The difference between the operators and logical operators

flink yarn-session的两种使用方式
随机推荐
flink部署操作-flink on yarn集群安装部署
IJCAI 2022|边界引导的伪装目标检测模型BGNet
序列基础练习题
flink项目开发-flink的scala shell命令行交互模式开发
原来何恺明提出的MAE还是一种数据增强
JSX基础
基于Flink CDC实现实时数据采集(二)-Source接口实现
day7-列表作业(1)
ES6 新特性:Class 的继承
Machine Learning (1) - Machine Learning Fundamentals
轻松接入Azure AD+Oauth2 实现 SSO
flink实例开发-详细使用指南
【数据库和SQL学习笔记】3.数据操纵语言(DML)、SELECT查询初阶用法
华科提出首个用于伪装实例分割的一阶段框架OSFormer
基于Flink CDC实现实时数据采集(四)-Sink接口实现
鼠标放上去变成销售效果
Flutter 3.0升级内容,该如何与小程序结合
Flink Distributed Cache 分布式缓存
Flink EventTime和Watermarks案例分析
Using pip to install third-party libraries in Pycharm fails to install: "Non-zero exit code (2)" solution