title: TTS Received But No Voice Coming Out
body: <p>I am trying to use TextToSpeech but i have some strange problems.</p>
  
  <p>Let me explain my application's architecture simply. This application will be used for bus hours. Users can add their buses to notification. Server will notify subscribers if anything changes. I want to use TTS with this application.</p>
  
  <p>I implemented Android GCM and notification system, only problem is TTS.</p>
  
  <p><code>GCMIntentService.onMessage</code> method calls generateNotification method below:</p>
  
  <pre><code>public static void generateNotification(Context context, String message) {
          int icon = R.drawable.icon_small;
          long when = System.currentTimeMillis();
          NotificationManager notificationManager = (NotificationManager)
                  context.getSystemService(Context.NOTIFICATION_SERVICE);
          Notification notification = new Notification(icon, message, when);
          String title = context.getString(R.string.app_name);       
  
          Bundle b = new Bundle();
          b.putString(EXTRA_MESSAGE, message);
          b.putString(READABLE_MESSAGE, message);
  
          Intent notificationIntent = new Intent(context, BusAlerts.class);
          notificationIntent.putExtra("CallType", CallType.NOTIFICATION);
          notificationIntent.putExtra("MessageReceived", b);
          // set intent so it does not start a new activity
          notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                  Intent.FLAG_ACTIVITY_NEW_TASK);
          PendingIntent intent =
                  PendingIntent.getActivity(context, 0, notificationIntent,  Intent.FLAG_ACTIVITY_NEW_TASK);
          notification.setLatestEventInfo(context, title, message, intent);
          notification.flags |= Notification.FLAG_AUTO_CANCEL;
          notification.defaults |= Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND;
          long[] vibrate = { 1000 };
          notification.vibrate = vibrate;          
          notificationManager.notify(0, notification);
      }
  </code></pre>
  
  <p>This code successfully generates notification. Here is BusAlerts.codes (some trimmed ;))</p>
  
  <pre><code>public class BusAlerts extends Activity implements OnInitListener {
  private static TextToSpeech myTts;
  
  @Override
      public void onCreate(Bundle savedInstanceState) {
          myTts = new TextToSpeech(this, null);
  }
  
  @Override
  protected void onStart() {
          super.onStart();
  
  //readableMessage extracts from bundles
  
  speak(readableMessage);
  }
  
  public void speak(String text)
      {
           myTts.speak(text, TextToSpeech.QUEUE_FLUSH, null);     
      }
  @Override
      protected void onDestroy() {
          // TODO Auto-generated method stub
          super.onDestroy();
           if (myTts != null) {
               myTts.shutdown();
               myTts.stop();
               myTts = null;
              }
      }
  public void onInit(int status) {
           if (status == TextToSpeech.SUCCESS) {
  
                  int result = myTts.setLanguage(Locale.UK);
  
                  if (result == TextToSpeech.LANG_MISSING_DATA
                          || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                      Log.e("TTS", "This Language is not supported");
                  } 
                  else{
                      if (myTts.isLanguageAvailable(Locale.UK) == TextToSpeech.LANG_AVAILABLE || myTts.isLanguageAvailable(Locale.UK) == TextToSpeech.LANG_COUNTRY_AVAILABLE)
                          myTts.setLanguage(Locale.UK);
                  }
  
              } else {
                  Log.e("TTS", "Initilization Failed!");
              }
  
      }
  </code></pre>
  
  <p>If users open this class from notification, everything works perfect but no sound coming out. When i debug it i see a situation as below.
  <img src="https://i.stack.imgur.com/PEtsb.png" alt="enter image description here"></p>
  
  <p>But if user presses Home button and reopens application (same activity resumes) user can hear sound.
  Its situation is like this.
  <img src="https://i.stack.imgur.com/zvjXG.png" alt="enter image description here"></p>
  
  <p>As i noticed mCachedParamters and mITts differs; but i don't know why.
  I have been stucked it for a week and couldn't find solution.</p>