title: To call an Activity after the text has spoken in the current activity in Android text to speech app
body: <p>I am new to android. Can any one help me with the following requirement; to call an activity after the speech of the current activity has completed. </p>
  
  <p>The text of activity2 is read after completion of activity1 but activity2 is launched before activity1 text is completed. In this utterance id is also not identified. </p>
  
  <p>The code I have written is follows. Any help would be appreciated. Thanks. </p>
  
  <pre><code> public void onInit(int status) {       
      if (status == TextToSpeech.SUCCESS) {
  
          String text= tt.getText().toString();
          if (text!=null &amp;&amp; text.length()&gt;0) {
       Toast.makeText(activity1.this, "Speaking: " + text, Toast.LENGTH_LONG).show();
  
       tts.setOnUtteranceCompletedListener(this);
       HashMap&lt;String, String&gt; myHash = new HashMap();
  
       tts.speak(text, TextToSpeech.QUEUE_ADD, myHash);
       myHash.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
      "completed");
  
       } 
      else if (status == TextToSpeech.ERROR) {
          Toast.makeText(Fossils.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);
      }
   }   
  </code></pre>