Android AIDL实现进程间通讯IPC

以下是一个简单的实现:

1.AIDLServer提供数据接口

①创建.aidl文件,公开接口给Client:

package com.example.aidlserver.aidl;

interface DataService{

int getData(String type);

String getTime();

}

② 对应的Service,实现aidl中对应的方法:

package com.example.aidlserver.service;

import com.example.aidlserver.aidl.DataService;

import android.app.Service;

import android.content.Intent;

import android.os.IBinder;

import android.os.RemoteException;

public class TestService extends Service {

@Override

public IBinder onBind(Intent intent) {

return binder;

}

private final DataService.Stub binder = new DataService.Stub() {

@Override

public int getData(String type) throws RemoteException {

return 5;

}

@Override

public String getTime() throws RemoteE

你可能感兴趣的:(android)