android aidl参数,AIDL 传递参数有关问题

AIDL 传递参数问题

请教各路大神帮忙指导指导。

我要对外写一个接口, 以通知其它进程相关信息:

package com.example.music.aidl;

interface IMusicNotification{

void onProgressUpdated(int progress, int max) ;

void onStopped();

void onBegin();

}

然后 需要对这个notification进行注册,也写一个AIDL:

package com.example.music.aidl;

import com.example.music.aidl.IMusicNotification;

interface MusicConnector {

void registerNotification(out IMusicNotification notifcation);

void unregisterNotification(out IMusicNotification notifcation);

void play();

void playnext();

在我的Service里,写成:

private ArrayList mReceivers = new ArrayList();

private MusicConnector.Stub mBinder = new MusicConnector.Stub() {

@Override

public void registerNotification(IMusicNotification notifcation)

throws RemoteException {

Log.d(TAG, "register( "+notifcation+" );");  //远程的notification传递过来,这里输出null,导致无法注册。

mReceivers.add(notifcation);

Log.d(TAG, "after registered,size: "+mReceivers.size());

}

@Override

public void unregisterNotification(IMusicNotification notifcation) throws RemoteException{

LogUtil.d(TAG, "unregister("+notifcation+")");

mReceivers.remove(notifcation);

}

};

我在另一个进程里注册时,发现无法传递IMusicNotification对象

private void IMusicNotification notification;

public void onServiceConnected(ComponentName name, IBinder service) {

Log.d(TAG, "onServiceConnected.^^");

musicConn=MusicConnector.Stub.asInterface(service);

try {

LogUtil.d(TAG, "try to register:"+notification); //notification这里这边 非null

musicConn.registerNotification(notification); //notification无法传递到远程Service去执行注册

} catch (RemoteException e) {

Log.e(TAG, "register failed!");

e.printStackTrace();

}

}

请教各路大神帮忙指导指导。

------解决思路----------------------

请把下面这段方法覆写去掉,或者返回有效的IBinder,而不是null

@Override

public IBinder asBinder() {

// TODO Auto-generated method stub

return null;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值