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;
}