0

I am trying to implement an intent to take the user back to the home screen once the TextToSpeech function completes, but it isn't working, and I'm not sure why. Here is my code:

public void playText(){     
    String text = typeNewMessageEditText.getText().toString();
    HashMap<String, String> myHashRender = new HashMap<String, String>();
    myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "completed");
    tts.speak(text, TextToSpeech.QUEUE_FLUSH, myHashRender);        
}


@Override
public void onUtteranceCompleted(String utteranceId) {
    if (utteranceId.equals("completed")){   
                Intent displayMainActivity = new Intent (this, MainActivity.class);
                startActivity(displayMainActivity);
    }   
}
Hoan Nguyen
  • 18,033
  • 3
  • 50
  • 54
embersofadyingfire
  • 523
  • 1
  • 4
  • 16
  • What is not working? does the it crash? – Hoan Nguyen Apr 20 '13 at 00:12
  • The TextToSpeech function completes, and does nothing, like onUtteranceCompleted is not being called or something... – embersofadyingfire Apr 20 '13 at 00:32
  • 1
    put a log inside onUtteranceCompleted. Log.d("TEST", "onUtteranceCompleted"); and see if the logcat log it. – Hoan Nguyen Apr 20 '13 at 00:44
  • I've stumbled upon some info in other posts that shouldn't have worked because in Eclipse, the SetOnUtteranceCompletedListener method is said to be deprecated, but I went ahead and set this method in onInit, and now my intent works within OnUtteranceCompletedListener....??? How does a deprecated method still work? Anyways, thanks for the help Hoan! – embersofadyingfire Apr 21 '13 at 22:19

0 Answers0