我的应用程序中有两个按钮,一个是启动 Google Voice,另一个是退出应用程序。但是,当我按下语音按钮时,它不会做任何事情,直到我按下退出按钮之后。因此,应用程序退出,但随后 Google Voice 启动。
public void onClick(View v) {
switch(v.getId()){
case R.id.btnDisable:{
//Set the ringer to normal
audio.setRingerMode(2);
//Close the text-to-speech engine
tts.shutdown();
//Welcome.bt.disable();
activity.finish();
onDestroy();
break;
}
case R.id.btnVoice: {
System.out.println ("pressed");
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en_US");
try {
startActivityForResult(intent, RESULT_SPEECH);
} catch (ActivityNotFoundException a) {
Toast t = Toast.makeText(getApplicationContext(),
"Opps! Your device doesn't support Speech to Text",
Toast.LENGTH_SHORT);
t.show();
}
break;
}
}
}