当前位置:网站首页>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();
}边栏推荐
- 【论文精读】Rich Feature Hierarchies for Accurate Object Detection and Semantic Segmentation(R-CNN)
- 解决:Unknown column ‘id‘ in ‘where clause‘ 问题
- 【MySQL】数据库多表链接的查询方式
- 【Pytorch学习笔记】10.如何快速创建一个自己的Dataset数据集对象(继承Dataset类并重写对应方法)
- [Go through 7] Notes from the first section of the fully connected neural network video
- 如何编写一个优雅的Shell脚本(三)
- day7-列表作业(1)
- Flink 状态与容错 ( state 和 Fault Tolerance)
- 学习总结week2_5
- Mesos learning
猜你喜欢

ECCV2022 | RU & Google propose zero-shot object detection with CLIP!

Mesos learning

AIDL详解

【After a while 6】Machine vision video 【After a while 2 was squeezed out】

【数据库和SQL学习笔记】9.(T-SQL语言)定义变量、高级查询、流程控制(条件、循环等)

Lecture 4 Backpropagation Essays

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

Using pip to install third-party libraries in Pycharm fails to install: "Non-zero exit code (2)" solution

【Pytorch学习笔记】8.训练类别不均衡数据时,如何使用WeightedRandomSampler(权重采样器)
![[Go through 8] Fully Connected Neural Network Video Notes](/img/0a/8b2510b5536621f402982feb0a01ef.png)
[Go through 8] Fully Connected Neural Network Video Notes
随机推荐
【数据库和SQL学习笔记】4.SELECT查询2:排序(ORDER BY)、聚合函数、分组查询(GROUP BY)
MSRA提出学习实例和分布式视觉表示的极端掩蔽模型ExtreMA
大型Web网站高并发架构方案
[Go through 9] Convolution
【After a while 6】Machine vision video 【After a while 2 was squeezed out】
学习总结week2_2
拿出接口数组对象中的所有name值,取出同一个值
神经网络也能像人类利用外围视觉一样观察图像
【Over 15】A week of learning lstm
Lecture 4 Backpropagation Essays
【Pytorch学习笔记】11.取Dataset的子集、给Dataset打乱顺序的方法(使用Subset、random_split)
解决端口占用问题
Flink和Spark中文乱码问题
The difference between the operators and logical operators
flink实例开发-详细使用指南
基于Flink CDC实现实时数据采集(二)-Source接口实现
flink项目开发-flink的scala shell命令行交互模式开发
【Pytorch学习笔记】9.分类器的分类结果如何评估——使用混淆矩阵、F1-score、ROC曲线、PR曲线等(以Softmax二分类为例)
门徒Disciples体系:致力于成为“DAO世界”中的集大成者。
【论文精读】ROC和PR曲线的关系(The relationship between Precision-Recall and ROC curves)