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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > ChatGpt >内容正文

ChatGpt

android 使用AIDL实现进程间通讯

發布時間:2023/12/10 ChatGpt 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 使用AIDL实现进程间通讯 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、創建服務端

?

1、首先創建AIDL文件

?

2、創建service,綁定AIDL接口

3、配置service

<service android:name=".AidlService"android:enabled="true"android:exported="true"><intent-filter android:priority="1000"><action android:name="AIDL.service"></action></intent-filter> </service>

?

4、開啟service和打開ServiceConnection

Intent intent=new Intent(getApplicationContext(),AidlService.class); bindService(intent,serviceConnection,BIND_AUTO_CREATE);

?----------------------------------------服務端創建完畢-------------------------------------------------------------

?

二、創建客戶端

1、同樣開始創建AIDL文件——與服務端的AIDL文件一樣(復制即可)

?

2、創建serviceConnection

private ServiceConnection serviceConnection=new ServiceConnection() {@Overridepublic void onServiceConnected(ComponentName componentName, IBinder iBinder) {Toast.makeText(getApplicationContext(),"已連接服務器",Toast.LENGTH_LONG).show();iAidlInterface=IAidlInterface.Stub.asInterface(iBinder);try {iAidlInterface.asBinder().linkToDeath(mDeathRecipient, 0);iAidlInterface.registerCallBack(iAidlCallBack);messages.addAll(iAidlInterface.getMessages());listView.setAdapter(arrayAdapter=new ArrayAdapter<>(getApplicationContext(),android.R.layout.simple_list_item_1,messages));} catch (RemoteException e) {e.printStackTrace();}}@Overridepublic void onServiceDisconnected(ComponentName componentName) {} };

3、開啟綁定服務端的service連接serviceConnection

Intent intent=new Intent(); String ACTION = "AIDL.service"; intent.setAction(ACTION); intent.setPackage("com.dlc.mytestttt"); bindService(intent,serviceConnection,BIND_AUTO_CREATE);

demo實現:https://download.csdn.net/download/meixi_android/12347788

總結

以上是生活随笔為你收集整理的android 使用AIDL实现进程间通讯的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。