Stop / shutdown failed: not tied to TTS engine

I have an android activity that is using TTS, but when I log out, you get a missing Connection Connection error in Logcat. Above the leaked service error, I get the expression that:

stop failed: not bound to TTS engine
shutdown failed: not bound to TTS engine

      

My onStop and onDestroy looks like this EDIT code:

@Override
public void onStop() {
    if (tts != null) {
    tts.stop();
    }
    super.onStop();
}

@Override
public void onDestroy() {
    if (tts != null) {
        tts.shutdown();
    }
    super.onDestroy();
}

      

I start TTS when the user clicks a button (TTS works fine, I'm just trying to fix the service connection error)

if (v == speakButton && ttscrashprotect == 1) {   
    String text = inputText.getText().toString();
    if (text != null && text.length() > 0) {
        tts.speak(text, TextToSpeech.QUEUE_ADD, null);
    }

      

This is my onActivityResult

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == MY_DATA_CHECK_CODE) {
        if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
            //sucess with TTS create it
            tts = new TextToSpeech(this, this);
        }
        else {
            //missing TTS so install it
            Intent installIntent = new Intent();
            installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installIntent);
        }
    }

      

TTS is working fine and I can see that the engine is being called in logcat, but for some reason tts.stop()

and tts.shutdown()

not tied to the same engine.

EDIT2: I seem to be connecting to the TTS engine and service more than once. Every time the text I want TTS to speak during the action, there is a different connection to the TTS engine and the TTS service.

My TTS code when changing text looks like this:

if (v==nextButton && progressL1<100) {
    Video.setVisibility(View.INVISIBLE); //hide the video view

    progressL1= progressL1 + 10;
    //increase progress by 10 and then load the new files
    //load the TTS text data from Asset folder progressL1 txt file
    Advanced.this.loadDataFromAsset(progressL1);
    //try some tts stuff here
    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);

      

TTS is started from the above code v == speakButton

.

+3


source to share


1 answer


Don't call tts.shutdown()

twice, just c onDestroy()

will be enough.



@Override
public void onStop() {
    if (tts != null) {
        tts.stop();
    }
    super.onStop();
}

@Override
public void onDestroy() {
    if (tts != null) {
        tts.shutdown();
    }
    super.onDestroy();
}

      

+2


source







All Articles