Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Binder建模问题-MusicStore,IMusicStore.aidl,Music,IMusic.aidl_Android_Api_Ipc_Modeling_Aidl - Fatal编程技术网

Android Binder建模问题-MusicStore,IMusicStore.aidl,Music,IMusic.aidl

Android Binder建模问题-MusicStore,IMusicStore.aidl,Music,IMusic.aidl,android,api,ipc,modeling,aidl,Android,Api,Ipc,Modeling,Aidl,Android Binder文档有一个简单的例子,关于如何通过Binder接口传递一个对象Rect,我想知道如果对象本身有一些同样由AIDL接口定义的方法,如何进行建模 例如,项目A拥有MusicStoreManager,项目B拥有MusicStore和Music,交互是通过绑定器IPC进行的。我使用IMusicStore.aidl定义了一个方法“IMusic getMusic(int musicId)”,IMusic.aidl定义了一个方法“byte[]getMusicData(int-fro

Android Binder文档有一个简单的例子,关于如何通过Binder接口传递一个对象Rect,我想知道如果对象本身有一些同样由AIDL接口定义的方法,如何进行建模

例如,项目A拥有MusicStoreManager,项目B拥有MusicStore和Music,交互是通过绑定器IPC进行的。我使用IMusicStore.aidl定义了一个方法“IMusic getMusic(int musicId)”,IMusic.aidl定义了一个方法“byte[]getMusicData(int-from,int-to)”,但我被困在这里:

  • 通常,如何在项目B上建模Music类、IMusic接口和IMusic.stub

  • getMusic()方法是否应该或可以在以下代码中返回IMusic.Stub实例或音乐实例

  • 如何理解音乐存根

  • 课堂音乐是否必须实现IMusic接口以及可包裹

  • 非常感谢-我真的很困惑

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

    好的,我可以告诉您一个有效的方法:对于通过AIDL定义的接口,始终创建
    .Stub
    类的实例。不要在其他类上随机应用该接口

    例如,项目A拥有MusicStoreManager,项目B拥有MusicStore和Music


    项目B应该创建
    IMusicStore.Stub
    IMusic.Stub
    的子类
    MusicStoreService
    将从
    onBind()
    返回
    IMusicStore.Stub
    类的实例,因此Project A可以通过
    bindService()
    获取
    IMusicStore
    代理。在
    IMusicStore.Stub
    类上实现
    getMusic()
    将返回
    IMusic.Stub
    类的实例。

    感谢您的快速回复。IMusic.Stub()构造函数没有参数,即如何将Stub对象与真实的音乐对象关联,因为MusicStore包含所有音乐对象的HashMap。getMusic()方法应该返回音乐对象类型还是IMusic接口类型?谢谢。@user506376:这里没有“真正的音乐对象”,AFAICT。在IMusic.Stub子类上放置“真正的音乐对象”智能。“getMusic()方法应该返回音乐对象类型还是IMusic接口类型?”--它必须返回
    IMusic.Stub
    AFAIK。如果IMusic.aidl的名称更改为IMusicAccessor.aidl,则可以创建api将音乐id与internel Music对象关联(打开、创建、获取等)。但这不是我真正想要的。我的问题是,我是否可以同时使用活页夹IPC,仍然符合接口定义?换句话说,是否有可能在面向对象的API风格中对面向服务的IPC机制进行建模?谢谢。@user506376:你对我来说不再有意义了,所以我不能再帮你了。终于让它工作了——存根对象就是音乐对象。谢谢你的帮助。