日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人工智能 > ChatGpt >内容正文

ChatGpt

AIDL注意细节 简单Demo

發(fā)布時間:2025/3/21 ChatGpt 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 AIDL注意细节 简单Demo 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

服務(wù)端

服務(wù)端注意細(xì)節(jié)

  • 不支持short數(shù)據(jù)類型
  • 支持的數(shù)據(jù)類型有:int、long、char、boolean、float、double、String、CharSequence、List、Map
  • 除了基本類型外,自定的類型需要我們通過實(shí)現(xiàn)Parcelable來序列化
  • 自定義的數(shù)據(jù)類型所在的包必須與aidl下文件擁有相同的包名
  • 除基本類型外,自定的類型必須標(biāo)注in、out、inout標(biāo)示數(shù)據(jù)的方向?;绢愋湍J(rèn)方向?yàn)閕n。通常報錯就處于此條

AIDL文件

package com.android.server;import android.os.Parcel; import android.os.Parcelable;/*** 自定義數(shù)據(jù)類型*/ public class Rectangular implements Parcelable{public int left;public int right;public int top;public int bottom;public Rectangular(){}public Rectangular(Parcel in){readFromParcel(in);}@Overridepublic int describeContents() {return 0;}@Overridepublic void writeToParcel(Parcel dest, int flags) {dest.writeInt(left);dest.writeInt(right);dest.writeInt(top);dest.writeInt(bottom);}public void readFromParcel(Parcel in){left = in.readInt();right = in.readInt();top = in.readInt();bottom = in.readInt();}public static final Parcelable.Creator<Rectangular> CREATOR = new Parcelable.Creator<Rectangular>(){@Overridepublic Rectangular createFromParcel(Parcel source) {return new Rectangular(source);}@Overridepublic Rectangular[] newArray(int size) {return new Rectangular[size];}}; }



Rectangular.aidl

package com.android.server;parcelable Rectangular;



IRemoteService.aidl

package com.android.server;import com.android.server.Rectangular;interface IRemoteService {void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,double aDouble, String aString);int getArea(in Rectangular rect);}


客戶端

客戶端注意細(xì)節(jié)

  • aidl文件必須與服務(wù)端一致,包括包名
  • 服務(wù)端每次修改aidl文件之后,必須更新客戶端的aidl文件,負(fù)責(zé)會服務(wù)綁定到服務(wù)端的服務(wù)。


Demo完整實(shí)現(xiàn)

https://github.com/xkck/AIDLServer

《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的AIDL注意细节 简单Demo的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。