Android Binder 文档有一个关于如何通过 Binder 接口传递对象 Rect 的简单示例,我想知道如果对象本身有一些也由 AIDL 接口定义的方法,如何进行建模?
比如项目A拥有MusicStoreManager,项目B拥有MusicStore和Music,交互是通过Binder IPC。我正在使用 IMusicStore.aidl 定义了一个方法“IMusic getMusic(int musicId)”,而 IMusic.aidl 定义了一个方法“byte[] getMusicData(int from, int to)”,但我被困在这里:
一般如何对项目B上的Music类、IMusic接口和IMusic.stub进行建模?
getMusic() 方法是否应该或可以在以下代码中返回 IMusic.Stub 实例或 Music 实例?
如何理解 IMusic.Stub?
Music 类是否必须实现 IMusic 接口以及 Parcelable?
非常感谢 - 我真的很困惑。
public class MusicStoreService extends Service {
...
protected static final IMusicStore.Stub store = new IMusicStore.Stub() {
...
public IMusic getMusic(int id) throws RemoteException {
return new Music(id); // or return new IMusic.Stub() ???
}
}
...
protected static final IMusic.Stub music = new IMusic.Stub() {
...
public byte[] getMusicData(int from, int to) throws RemoteException {
// open the associated file, read the data within range, return it back.
}
}
...
}
public class Music extends Object implements Parcelable, IMusic {
...
public byte[] getMusicData(int from, int to) throws RemoteException {
// open the associated file, read the data within range, return it back.
}
...
}