I am using the TTS in my APP. During onPuase method, I use the following code to stop the engine. The problem is whenever I pause the activity say using home button, I get the error as I have pasted in the log cat section. I understand from the log cat (Activity com.example.DragDrop.PlaySeries has leaked ServiceConnection ) the problem is due to some leakage. However the issue is not stoping my app or disturbs any functionality. But I would like to know the seriousness of this issue and how to avoid this ?
Please help
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.i("PlaySeries", "In pause play series");
if(tts !=null){
Log.i("PlaySeries", "In pause play series");
tts.stop();
// tts.shutdown();
}
}
@Override
protected void onDestroy() {
//Close the Text to Speech Library
if(tts !=null){
Log.i("PlaySeries", "In pause play series");
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
and in onCreate
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.series);
tts = new TextToSpeech(this,this);
}
03-22 10:46:45.205: E/ActivityThread(3881): Activity com.example.DragDrop.PlaySeries has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection@2bbe5960 that was originally bound here03-22 10:46:45.205: E/ActivityThread(3881): android.app.ServiceConnectionLeaked: Activity com.example.DragDrop.PlaySeries has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection@2bbe5960 that was originally bound here03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): android.app.ServiceConnectionLeaked: Activity com.example.DragDrop.PlaySeries has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection@2bbe5960 that was originally bound here03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881): 03-22 10:46:45.205: E/ActivityThread(3881):
03-22 10:46:45.205: E/ActivityThread(3881):
I had a similar error when I made the TTS object static (so the TTS continues speaking even when the device is rotated). The leak was triggered when the device was rotated so the screen changed between portrait and landscape modes.
For a while I was perplexed as the error was only reported on some older devices running earlier versions of Android. However once I discovered the fix I suspect the problem was common to all devices and versions, but possibly masked on the newer models.
The fix was to initialize the TTS object with the Application Context, rather than the current (Activity) context.
Here's my code
tts = new TextToSpeech(getApplicationContext(), this);
and the complete diff is available at: http://code.google.com/p/android-tts-experiments/source/detail?r=b879fd1042151cbebc736b89a9fb660c895081ea
Just have this code onDestroy
@Override
protected void onDestroy()
{
super.onDestroy();
tts.shutdown();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With