2013-05-13 39 views
0

我用意圖語音識別,這裏是代碼:的Android RecognizerIntent簡單的破壞

/** 
* Fire an intent to start the voice recognition activity. 
*/ 
private void startVoiceRecognitionActivity() 
{ 
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, 
      RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice recognition Demo..."); 
    startActivityForResult(intent, REQUEST_CODE); 
} 

,一切工作正常。例如,現在我想在5秒後停止語音識別。我無法想象如何殺死語音識別活動。

+0

你可以使用處理程序? – Sam 2013-05-13 09:38:51

+0

我以爲Handler只是在一段時間後纔開始行動。它是否可以通過意圖關閉活動發佈? – 2013-05-13 09:42:08

+1

這裏提到的解決方案有什麼? http://stackoverflow.com/questions/7361987/how-to-stop-an-app-after-some-time – sandkasten 2013-05-13 09:52:06

回答

2

要殺死語音識別活動,請致電finishActivity(REQUEST_CODE)
因此,您需要在5秒的時間內設置一個倒數計時器,在onFinish請致電finishActivity(REQUEST_CODE)。你打電話後啓動計時器startActivityForResult

+0

完美的謝謝。 – 2013-05-13 10:25:35