summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/java/android/speech/RecognitionService.java13
-rw-r--r--core/java/android/speech/SpeechRecognizer.java8
2 files changed, 20 insertions, 1 deletions
diff --git a/core/java/android/speech/RecognitionService.java b/core/java/android/speech/RecognitionService.java
index 32b2d8f..45eb0bf 100644
--- a/core/java/android/speech/RecognitionService.java
+++ b/core/java/android/speech/RecognitionService.java
@@ -91,9 +91,20 @@ public abstract class RecognitionService extends Service {
}
};
- private void dispatchStartListening(Intent intent, IRecognitionListener listener) {
+ private void dispatchStartListening(Intent intent, final IRecognitionListener listener) {
if (mCurrentCallback == null) {
if (DBG) Log.d(TAG, "created new mCurrentCallback, listener = " + listener.asBinder());
+ try {
+ listener.asBinder().linkToDeath(new IBinder.DeathRecipient() {
+ @Override
+ public void binderDied() {
+ mHandler.sendMessage(mHandler.obtainMessage(MSG_CANCEL, listener));
+ }
+ }, 0);
+ } catch (RemoteException re) {
+ Log.e(TAG, "dead listener on startListening");
+ return;
+ }
mCurrentCallback = new Callback(listener);
RecognitionService.this.onStartListening(intent, mCurrentCallback);
} else {
diff --git a/core/java/android/speech/SpeechRecognizer.java b/core/java/android/speech/SpeechRecognizer.java
index 91c3799..88e2ede 100644
--- a/core/java/android/speech/SpeechRecognizer.java
+++ b/core/java/android/speech/SpeechRecognizer.java
@@ -396,6 +396,14 @@ public class SpeechRecognizer {
* Destroys the {@code SpeechRecognizer} object.
*/
public void destroy() {
+ if (mService != null) {
+ try {
+ mService.cancel(mListener);
+ } catch (final RemoteException e) {
+ // Not important
+ }
+ }
+
if (mConnection != null) {
mContext.unbindService(mConnection);
}