0

为了使用自定义aidl,我们想创建一个service classServerbindService() )并且我们想在我们想要访问aidl接口方法(Client )的类中绑定service(),但是当涉及到第三方aidl文件时,我们只是可以调用aidl接口并使用它,所以我的问题是“我们应该要 bindService 吗?

在自定义aidl文件中绑定服务,如下所示

Intent intentService=new Intent(ClientActivity.this,BindService.class);
bindService(intentService,serviceConnection,Context.BIND_AUTO_CREATE);

服务连接

/*
    * Service Connection - init the aidl interface when the service connected
    * */
    ServiceConnection serviceConnection=new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            Log.d(TAG, "onServiceDisconnected:-service connected");

            CustomAidl=CustomAidl.Stub.asInterface(iBinder);
        }

        @Override
        public void onServiceDisconnected(ComponentName componentName) {
            Log.d(TAG, "onServiceDisconnected:-service disconnected");
        }
    };
4

0 回答 0