views:

62

answers:

2

I added TextToSpeech to my app, following the guidelines in the following post:

http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html

and now my onDestroy is no longer called when the back button is pressed. I filed a bug report regarding this: http://code.google.com/p/android/issues/detail?id=7674

Figured i should also ask here if someone else has seen this, and found a solution?

It seems that it is the intent that causes the problem, i.e. the following:

Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);

If I skip this intent, and just go ahead and create a tts-instance, it works fine. Any clues to what is wrong with this intent?

+1  A: 

Think I've figured this one out. My problem is that I was assuming that onDestroy would be called when my activity finished, so that I could store the state (and preferences, et c). And I assumed that onDestroy would always happen before a new instance of the activity was created, so that the new instance in onCreate could load the state stored by the old instance.

This does not hold in general. It does not even hold true for onStop.

The solution for me was simply to save what I wanted in onPause. It seems I can count on this one being called before any new instance can be created. But since onPause is called in many cases where I don't need to save, I also check isFinishing(). I.e. if isFinishing() in onPause, then I save.

Note that it didn't seem to matter if I launched my activity in singleTop mode, I would still get two "alive" instances. One which was on its way to being destroyed (onPause was called but was yet to enter onStop or onDestroy) and one which was in onCreate.

Anyway, I hope I've solved it now.

hermo