aidl 中通过RemoteCallbackList 运用到的回调机制: service回调activity的方法
来源:互联网 发布:手机手柄连接软件 编辑:程序博客网 时间:2024/05/22 07:47
说明:我没有写实例代码,直接拿项目中的代码,有点懒了,这里我省略贴出两个aidl文件。
TtsService extends Service
- private final RemoteCallbackList<ITtsCallback> mCallbacks
- = new RemoteCallbackList<ITtsCallback>();
- private final RemoteCallbackList<ITtsCallback> mCallbacks = new RemoteCallbackList<ITtsCallback>();
- private final android.speech.tts.ITts.Stub mBinder = new Stub() {
- public int registerCallback(String packageName, ITtsCallback cb) {
- if (cb != null) {
- mCallbacks.register(cb);
- mCallbacksMap.put(packageName, cb);
- return TextToSpeech.SUCCESS;
- }
- return TextToSpeech.ERROR;
- }
- public int unregisterCallback(String packageName, ITtsCallback cb) {
- if (cb != null) {
- mCallbacksMap.remove(packageName);
- mCallbacks.unregister(cb);
- return TextToSpeech.SUCCESS;
- }
- return TextToSpeech.ERROR;
- }
- public int speak(String callingApp, String text, int queueMode, String[] params) {
- ArrayList<String> speakingParams = new ArrayList<String>();
- if (params != null) {
- speakingParams = new ArrayList<String>(Arrays.asList(params));
- }
- return this.speak(callingApp, text, queueMode, speakingParams);
- }
- private final android.speech.tts.ITts.Stub mBinder = new Stub() { public int registerCallback(String packageName, ITtsCallback cb) { if (cb != null) { mCallbacks.register(cb); mCallbacksMap.put(packageName, cb); return TextToSpeech.SUCCESS; } return TextToSpeech.ERROR; } public int unregisterCallback(String packageName, ITtsCallback cb) { if (cb != null) { mCallbacksMap.remove(packageName); mCallbacks.unregister(cb); return TextToSpeech.SUCCESS; } return TextToSpeech.ERROR; } public int speak(String callingApp, String text, int queueMode, String[] params) { ArrayList<String> speakingParams = new ArrayList<String>(); if (params != null) { speakingParams = new ArrayList<String>(Arrays.asList(params)); } return this.speak(callingApp, text, queueMode, speakingParams); }
- private void dispatchProcessingCompletedCallback(String packageName) {
- ITtsCallback cb = mCallbacksMap.get(packageName);
- if (cb == null){
- return;
- }
- //Log.i("TtsService", "TTS callback: dispatch started");
- // Broadcast to all clients the new value.
- final int N = mCallbacks.beginBroadcast();
- try {
- cb.processingCompleted();
- } catch (RemoteException e) {
- // The RemoteCallbackList will take care of removing
- // the dead object for us.
- }
- mCallbacks.finishBroadcast();
- //Log.i("TtsService", "TTS callback: dispatch completed to " + N);
- }
- private void dispatchProcessingCompletedCallback(String packageName) { ITtsCallback cb = mCallbacksMap.get(packageName); if (cb == null){ return; } //Log.i("TtsService", "TTS callback: dispatch started"); // Broadcast to all clients the new value. final int N = mCallbacks.beginBroadcast(); try { cb.processingCompleted(); } catch (RemoteException e) { // The RemoteCallbackList will take care of removing // the dead object for us. } mCallbacks.finishBroadcast(); //Log.i("TtsService", "TTS callback: dispatch completed to " + N); }
- @Override
- public void onDestroy() {
- super.onDestroy();
- // TODO replace the call to stopAll() with a method to clear absolutely all upcoming
- // uses of the native synth, including synthesis to a file, and delete files for which
- // synthesis was not complete.
- stopAll();
- // Unregister all callbacks.
- mCallbacks.kill();
- }
- @Override public void onDestroy() { super.onDestroy(); // TODO replace the call to stopAll() with a method to clear absolutely all upcoming // uses of the native synth, including synthesis to a file, and delete files for which // synthesis was not complete. stopAll(); // Unregister all callbacks. mCallbacks.kill(); }
在activity中
- mITtscallback = new ITtsCallback.Stub() {
- public void processingCompleted() throws RemoteException {
- if (listener != null) {
- listener.onProcessingCompleted();
- }
- }
- };
- result = mITts.registerCallback(mPackageName, mITtscallback);
- mITtscallback = new ITtsCallback.Stub() { public void processingCompleted() throws RemoteException { if (listener != null) { listener.onProcessingCompleted(); } } }; result = mITts.registerCallback(mPackageName, mITtscallback);
0 0
- aidl 中通过RemoteCallbackList 运用到的回调机制: service回调activity的方法
- aidl 中通过RemoteCallbackList 运用到的回调机制: service回调activity的方法 .
- aidl 中通过RemoteCallbackList 运用到的回调机制: service回调activity的方法
- aidl 中通过RemoteCallbackList 运用到的回调机制: service回调activity的方法
- aidl 中通过RemoteCallbackList 运用到的回调机制: service回调activity的方法
- 探究---RemoteCallbackList---activity与service之间的联系
- android aidl通信 RemoteCallbackList客户端注册回调
- 从应用层通过aidl调用到frameworks中添加的服务的方法
- service中AIDL的应用
- Service 回调 Activity的方法。
- Service的运用与activity的通信
- 【Android】关于在Service中通过接口回调更新Activity的UI
- Android组件---Service,AIDL,Service与Activity之间的通信
- RemoteCallbackList的使用
- 通过 AIDL 分析 Binder 的工作机制
- 通过bindService方法实现Activity与Service的交互
- Android AIDL -通过一个比较完整的Demo快速运用
- Android AIDL -通过一个比较完整的Demo快速运用
- 数据结构实验之队列一:排队买饭
- AS(AndroidStudio)签名
- VC静态库的创建和使用
- 元组、列表、字典的基础知识和比较(二)
- 基本类型的递减排序简单实现
- aidl 中通过RemoteCallbackList 运用到的回调机制: service回调activity的方法
- 数据结构实验之二叉树的建立与遍历
- 传统存储老矣,新兴存储能当大任否?
- CXF的三种发布方式和客户端调用方法
- hdu 1712 ACboy needs your help
- HDOJ 1528 Card Game Cheater (模拟田忌赛马贪心)
- 多元函数极值及其求法
- 数据结构实验之求二叉树后序遍历和层次遍历
- 可能是计算机理论领域十年来最大的突破