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

flink实例开发-batch批处理实例

Flink 状态与容错 ( state 和 Fault Tolerance)

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

Thread handler句柄 IntentServvice handlerThread
![[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)](/img/ac/884d8aba8b9d363e3b9ae6de33d5a4.png)
[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)

服务网格istio 1.12.x安装

哥廷根大学提出CLIPSeg,能同时作三个分割任务的模型
![[Go through 7] Notes from the first section of the fully connected neural network video](/img/e2/1107171b52fe9dcbf454f7edcdff77.png)
[Go through 7] Notes from the first section of the fully connected neural network video

【零基础开发NFT智能合约】如何使用工具自动生成NFT智能合约带白名单可Mint无需写代码

Flink HA配置
随机推荐
鼠标放上去变成销售效果
js实现数组去重
flink基本原理及应用场景分析
ES6基础语法
神经网络也能像人类利用外围视觉一样观察图像
哥廷根大学提出CLIPSeg,能同时作三个分割任务的模型
redis cache clearing strategy
MySql之索引
如何编写一个优雅的Shell脚本(一)
A deep learning code base for Xiaobai, one line of code implements 30+ attention mechanisms.
Distributed and Clustered
In Opencv, imag=cv2.cvtColor(imag,cv2.COLOR_BGR2GRAY) error: error:!_src.empty() in function 'cv::cvtColor'
基于Flink CDC实现实时数据采集(二)-Source接口实现
SharedPreferences和SQlite数据库
【数据库和SQL学习笔记】9.(T-SQL语言)定义变量、高级查询、流程控制(条件、循环等)
Matplotlib(二)—— 子图
数据库期末考试,选择、判断、填空题汇总
【NFT开发】设计师无技术基础保姆级开发NFT教程在Opensea上全套开发一个NFT项目+构建Web3网站
华科提出首个用于伪装实例分割的一阶段框架OSFormer
day8字典作业