Android(安卓)AIDL基本步骤
16lz
2021-01-24
aidl 步骤 1 project- new aidl 文件,在src/main/aidl/底下 是一个接口文件 2 新建service 服务,新建 接口的庄对象,实现函数 private IBinder mIBinder = new IMyAidlInterface.Stub() { @Override public int getCount() throws RemoteException { LogUtil. d ( TAG , "getCount:" + mCount ); return mCount ; } @Override public void stopTimer() throws RemoteException { LogUtil. d ( TAG , "stopTimer" ); if ( timer != null ) { timer .cancel(); } } }; 3 在服务onBind 方法中,将binder 返回 4 通过服务的bind 绑定 private IMyAidlInterface mAidl ; private ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName name, IBinder service) { mAidl = IMyAidlInterface.Stub. asInterface (service); } public void onServiceDisconnected(ComponentName name) { mAidl = null ; } }; Intent intent1 = new Intent(getApplicationContext(), AidlService. class ); bindService(intent1, mConnection , BIND_AUTO_CREATE ); 绑定到服务,接收连接回调 连接上以后,转化拿到 aidl对象。断开时,置为空。
熟悉流程以后,主要是定义aidl 接口文件 然后做数据的交互
熟悉流程以后,主要是定义aidl 接口文件 然后做数据的交互
更多相关文章
- cocos2dx android
- Android输入框限制字符长度,字母自动大写
- Android(安卓)多媒体扫描过程
- Android中隐藏标题栏和状态栏(电源,信号,时间等信息)
- 〖Android〗我的ADT Eclipse定制
- Android系统Home应用程序(Launcher)的启动过程源代码分析
- registerActivityLifecycleCallbacks 的用途
- Android(安卓)实时视频采集
- Android(安卓)databinding 双向绑定(Demo)