title: how to stop text-speech when android app closed by user
body: <p>I'm looking for all kind of functions like onDestroy . but i'm exactly looking for a function that runs when app closed by user. i'm using text-speech in my application, but while it's speaking, if user close app(no matter how, force stop, or exit button in app , ...) it will keep speaking. is there any specific function for this?</p>
  
  <p>Thanks in advance</p>
  
  <p>Attirant</p>
  
  <p>code:</p>
  
  <pre><code>private boolean t1State = false;
  private TextToSpeech t1;
  
  private void start_voice(String text)
  {
      t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
          @Override
          public void onInit(int status) {
              if(status != TextToSpeech.ERROR) {
                  t1.setLanguage(Locale.UK);
              }
          }
      });
      String msg = "Voice Started";
      Toast.makeText(getApplicationContext(), msg,Toast.LENGTH_SHORT).show();
      t1.speak(text, TextToSpeech.QUEUE_FLUSH, null);
      t1State = true;
  }
  private void stop_voice()
  {
      String msg;
      if(t1 !=null) {
          t1.stop();
      }
      msg = "Voice has been Stopped";
      Toast.makeText(getApplicationContext(), msg,Toast.LENGTH_SHORT).show();
      t1State = false;
  }
  </code></pre>