Am new to android world and working on text-to-speech app, I got struck in between this app, The problem is my activity-2 image is appearing on screen before my activity-1 has completed reading its content.When i use the following code activity-2 is not starting at all.Any help would be appreciated .Thanks
if (status == TextToSpeech.SUCCESS) {
String text= tt.getText().toString();
if (text!=null && text.length()>0) {
Toast.makeText(activity1.this, "Speaking: " + text, Toast.LENGTH_LONG).show();
HashMap<String, String> myHash = new HashMap();
myHash.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
"completed");
tts.speak(text, TextToSpeech.QUEUE_ADD, myHash);
tts.setOnUtteranceCompletedListener(this);
}
else if (status == TextToSpeech.ERROR) {
Toast.makeText(activity1.this,
"Error occurred while initializing Text-To-Speech engine", Toast.LENGTH_LONG).show();
}
}
} public void onUtteranceCompleted(String t) {
if(t == "completed"){
Intent i = new Intent(this, activity2.class);
startActivity(i);
}
}
if (status == TextToSpeech.SUCCESS) {
String text= tt.getText().toString();
if (text!=null && text.length()>0) {
Toast.makeText(activity1.this, "Speaking: " + text, Toast.LENGTH_LONG).show();
HashMap<String, String> myHash = new HashMap();
myHash.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
"completed");
tts.speak(text, TextToSpeech.QUEUE_ADD, myHash);
tts.setOnUtteranceCompletedListener(this);
}
else if (status == TextToSpeech.ERROR) {
Toast.makeText(activity1.this,
"Error occurred while initializing Text-To-Speech engine", Toast.LENGTH_LONG).show();
}
}
} public void onUtteranceCompleted(String t) {
if(t == "completed"){
Intent i = new Intent(this, activity2.class);
startActivity(i);
}
}