SpeechRecognizer应仅用于服务中应用程序的主线程

时间:2014-01-28 03:05:09

标签: android android-service speech-recognition

我有使用SpeechRecognizer实现SpeechRecognization的服务类。有一个广播接收器类,它将在事件发生时启动该服务。然后SpeechRecognizer将开始收听服务。

我在执行此过程时遇到了运行时异常。

01-28 09:15:09.601: E/JavaBinder(23476): *** Uncaught remote exception!  (Exceptions are not yet supported across processes.)
01-28 09:15:09.601: E/JavaBinder(23476): java.lang.RuntimeException: SpeechRecognizer should be used only from the application's main thread
01-28 09:15:09.601: E/JavaBinder(23476):    at android.speech.SpeechRecognizer.checkIsCalledFromMainThread(SpeechRecognizer.java:319)
01-28 09:15:09.601: E/JavaBinder(23476):    at android.speech.SpeechRecognizer.startListening(SpeechRecognizer.java:260)
01-28 09:15:09.601: E/JavaBinder(23476):    at com.reader.MainSpeakerService.startRecognization(MainSpeakerService.java:181)
01-28 09:15:09.601: E/JavaBinder(23476):    at com.reader.MainSpeakerService.onUtteranceCompleted(MainSpeakerService.java:255)
01-28 09:15:09.601: E/JavaBinder(23476):    at android.speech.tts.UtteranceProgressListener$1.onDone(UtteranceProgressListener.java:57)
01-28 09:15:09.601: E/JavaBinder(23476):    at android.speech.tts.TextToSpeech$Connection$1.onDone(TextToSpeech.java:1443)
01-28 09:15:09.601: E/JavaBinder(23476):    at android.speech.tts.ITextToSpeechCallback$Stub.onTransact(ITextToSpeechCallback.java:63)
01-28 09:15:09.601: E/JavaBinder(23476):    at android.os.Binder.execTransact(Binder.java:388)
01-28 09:15:09.601: E/JavaBinder(23476):    at dalvik.system.NativeStart.run(Native Method)

根据android doc,the service uses your application's main thread。该服务在主线程上运行。我很困惑为什么在服务中发生这种异常。

0 个答案:

没有答案