当前位置:网站首页>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();
}边栏推荐
- ECCV2022 | RU&谷歌提出用CLIP进行zero-shot目标检测!
- AWS 常用服务
- flink实例开发-batch批处理实例
- Thread handler handle IntentServvice handlerThread
- Flink accumulator Counter 累加器 和 计数器
- Tensorflow踩坑笔记,记录各种报错和解决方法
- ECCV2022 | RU & Google propose zero-shot object detection with CLIP!
- 全尺度表示的上下文非局部对齐
- 基于Flink CDC实现实时数据采集(四)-Sink接口实现
- redis persistence
猜你喜欢

BFC详解(Block Formmating Context)

spingboot 容器项目完成CICD部署

Flink EventTime和Watermarks案例分析

【论文精读】Rich Feature Hierarchies for Accurate Object Detection and Semantic Segmentation(R-CNN)

【NFT开发】设计师无技术基础保姆级开发NFT教程在Opensea上全套开发一个NFT项目+构建Web3网站
![[Go through 4] 09-10_Classic network analysis](/img/f2/e6e71869b8ab014cc1eea0537fc2e7.png)
[Go through 4] 09-10_Classic network analysis

华科提出首个用于伪装实例分割的一阶段框架OSFormer

flink基本原理及应用场景分析

2022年中总结关键词:裁员、年终奖、晋升、涨薪、疫情

【NFT网站】教你制作开发NFT预售网站官网Mint作品
随机推荐
6k+ star,面向小白的深度学习代码库!一行代码实现所有Attention机制!
Matplotlib(三)—— 实践
day8字典作业
【论文精读】Rich Feature Hierarchies for Accurate Object Detection and Semantic Segmentation(R-CNN)
[Go through 7] Notes from the first section of the fully connected neural network video
Lecture 3 Gradient Tutorial Gradient Descent and Stochastic Gradient Descent
Flink HA安装配置实战
Flink Oracle CDC写入到HDFS
数据库期末考试,选择、判断、填空题汇总
es6迭代协议
HQL statement execution process
【Over 16】Looking back at July
flink实例开发-详细使用指南
[Go through 11] Random Forest and Feature Engineering
day7-列表作业(1)
面向小白的深度学习代码库,一行代码实现30+中attention机制。
ECCV2022 | RU&谷歌提出用CLIP进行zero-shot目标检测!
DOM and its applications
02.01-----The role of parameter reference "&"
学习总结week2_1