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