当前位置:网站首页>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();
}边栏推荐
猜你喜欢

记我的第一篇CCF-A会议论文|在经历六次被拒之后,我的论文终于中啦,耶!

flink yarn-session的两种使用方式

【数据库和SQL学习笔记】10.(T-SQL语言)函数、存储过程、触发器

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

MSRA提出学习实例和分布式视觉表示的极端掩蔽模型ExtreMA

【数据库和SQL学习笔记】5.SELECT查询3:多表查询、连接查询

Flink Broadcast 广播变量

CVPR best paper winner Huang Gao's team from Tsinghua University presented the first dynamic network review

用GAN的方法来进行图片匹配!休斯顿大学提出用于文本图像匹配的对抗表示学习,消除模态差异!

【数据库和SQL学习笔记】6.SELECT查询4:嵌套查询、对查询结果进行操作
随机推荐
DOM and its applications
HQL statement execution process
Mysql-连接https域名的Mysql数据源踩的坑
In Opencv, imag=cv2.cvtColor(imag,cv2.COLOR_BGR2GRAY) error: error:!_src.empty() in function 'cv::cvtColor'
发顶会顶刊论文,你应该这样写作
全尺度表示的上下文非局部对齐
序列基础练习题
js实现数组去重
npm搭建本地服务器,直接运行build后的目录
如何跟踪网络路由链路&检测网络健康状况
[After a 12] No record for a whole week
Matplotlib(一)—— 基础
The fourth back propagation back propagation
SSL 证书签发详细攻略
Flink 状态与容错 ( state 和 Fault Tolerance)
服务网格istio 1.12.x安装
[Skill] Long-term update
基于Flink CDC实现实时数据采集(三)-Function接口实现
Lecture 3 Gradient Tutorial Gradient Descent and Stochastic Gradient Descent
A deep learning code base for Xiaobai, one line of code implements 30+ attention mechanisms.