我在我的课程中使用android tts只是说一条消息,例如:问题:服务连接泄漏
public class WorkTimerNotification extends ActionBarActivity implements TextToSpeech.OnInitListener {
TextToSpeech tts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_work_timer_notification);
//line1
tts = new TextToSpeech(this,this);
@Override
public void onInit(int status) {
//line2
tts.setLanguage(Locale.US);
//line3
tts.speak("Text to say aloud", TextToSpeech.QUEUE_ADD, null);
tts.shutdown();
}
@Override
protected void onDestroy() {
super.onDestroy();
tts.shutdown();
}
第1行,我使用以下logcat泄漏了serviceConnection:
WorkTimerNotification has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection@41aee290 that was originally bound here
android.app.ServiceConnectionLeaked
我按此按钮,由于某种原因,它仍然返回哈希表。 我不知道为什么...
int speak(CharSequence, int, Bundle, String)
我也尝试过:但是它也不起作用。
@Override
protected void onDestroy() {
//Close the Text to Speech Library
if(tts!= null) {
tts.stop();
ttsRest.shutdown();
Log.d(TAG, "TTS Destroyed");
}
super.onDestroy();
}