如果您在Android模拟器上使用API 21和23运行以下代码(但有趣的是,不是API 22),并且终止应用程序(调用onDestroy),您将收到弹出错误"不幸的是,PICO TTS已经停止了。"
package com.example.boober.stackqttspicoerror;
import android.speech.tts.TextToSpeech;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import java.util.HashMap;
public class MainActivity extends AppCompatActivity {
TextToSpeech tts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final HashMap<String, String> map = new HashMap<String, String>();
map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "thisIsAUniqueID12345");
tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.ERROR) {
Log.i("XXX", "There was an error initializing the TTS");
} else {
tts.speak("hello", TextToSpeech.QUEUE_FLUSH, map);
}
}
});
}
@Override
protected void onDestroy() {
// un-commenting either or both of the proceeding lines does nothing
// to stop the "Unfortunately PICO TTS has stopped" error on API 21
// tts.shutdown();
// tts = null;
super.onDestroy();
}
}
文档建议(但不清楚).shutdown()方法旨在防止此类事情,但在这种情况下它似乎没有帮助。
因此,在用户关闭应用程序的任何时候,他们都会从PICO TTS获得此后续错误消息。
如何&#34;停止&#34;应用程序终止之前的PICO TTS是为了防止它独立触发此弹出窗口?
感谢您的任何想法!