how to block current activity till the TTS Engine is not  initialized
<p>i have developed an application which has to use TTS Engine.</p>

<p>Now the problem is i need to wait till the  TTS engine is initialized,though  i am using sleep method it is not working well.</p>

<p>here is my code</p>

<pre><code>public void onCreate(Bundle savedInstanceState) {

    ......

    Intent checkin = new Intent();
    checkin.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(checkin, MY_DATA_CHECKCODE1);
    //l.setOnTouchListener(this);

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

     tts.speak("Enter sms", TextToSpeech.QUEUE_FLUSH, null);
</code></pre>

<p>}</p>

<p>protected void onActivityResult(int requestCode, int resultCode, Intent data) {</p>

<p>if (requestCode == MY_DATA_CHECKCODE) {</p>

<pre><code>        if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {

            // success, create the TTS instance

            tts = new TextToSpeech(this, this);

            tts.setLanguage(Locale.US);

            tts.setSpeechRate((float) 0.4);


        } 
    }

}
</code></pre>

<p>instead of above  sleep method  i need to wait till the TTS Engine is not </p>

<p>initialized.so how can i write a neat block of code to resume the current activity after </p>

<p>TTS Engine is initialized, instead of doing a hard coding to check in a loop whether TTS </p>

<p>has been initialized.(i even dont know how to do this as well).     </p>

<p>The application is running in to Non-responding state and throwing Null pointer Exception </p>

<p>when I use
 tts.speak("Enter sms", TextToSpeech.QUEUE_FLUSH, null);</p>

<p>method. So please suggest me the solution to fix this problem. I have googled but could not find any suitable answer.</p>
