日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

android 使用AIDL实现进程间通讯

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

一、創(chuàng)建服務(wù)端

?

1、首先創(chuàng)建AIDL文件

?

2、創(chuàng)建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);

?----------------------------------------服務(wù)端創(chuàng)建完畢-------------------------------------------------------------

?

二、創(chuàng)建客戶端

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

?

2、創(chuàng)建serviceConnection

private ServiceConnection serviceConnection=new ServiceConnection() {@Overridepublic void onServiceConnected(ComponentName componentName, IBinder iBinder) {Toast.makeText(getApplicationContext(),"已連接服務(wù)器",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、開啟綁定服務(wù)端的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實(shí)現(xiàn):https://download.csdn.net/download/meixi_android/12347788

總結(jié)

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

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