I’m trying to implement speech recognition in my app. It loads the speech recognition panel fine, recognises what you say, then once it’s finished it’s supposed to return to the app calling the onActivityResult method. Unfortunately it doesn’t and just returns to the device home screen. Any ideas what I’m doing wrong?
static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
/**
* Handler from the listening thread
*/
public Handler mhandle = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MAXOVER_MSG :
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
break;
default :
super.handleMessage(msg);
break;
}
}
};
/**
* Handle the results from the recognition activity.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
Log.i("hmm","This never seems to get called..");
}
super.onActivityResult(requestCode, resultCode, data);
}
Your application is probably
finishing for some reason. Are you SINGLE_TOP or SINGLE_TASK or some other special function flag to start your Activity (either in the Intent that started it or in the AndroidManifest.xml)?