android - After setting new language: TextToSpeech.onInitListener is called before new TextToSpeech(..) instance is returned -
android - After setting new language: TextToSpeech.onInitListener is called before new TextToSpeech(..) instance is returned -
i ran unexpected problem oninit(..)
new texttospeech
instance on android.
all code samples found assume new instance returned caller before ononit(..)
called, homecoming value usable access new texttospeech
instance.
after changing default language phone activity restarted (as expected) , create new texttospeech
instance usual. in case oninit(..)
callback called before new texttospeech(..)
returns instance. setup in oninit(..)
uses outdated instance or null
.
public static void starttts() { tts_enabled = false; texttospeech = null; texttospeech = new texttospeech(starter/*context*/,new texttospeech.oninitlistener() { public void oninit(int status) { if(texttospeech==null) throw new runtimeexception("starttts.oninit: texttospeech=null"); boolean r = status==texttospeech.success; if(r) { init_tts(); tts_enabled = true; } else texttospeech = null; } }); }
basically, in example, exeption throws. i have tested on huawei u8510 android 2.3.3 , emulator android 2.1. what expected here?
i have resolved problem , showed, reason quite different assumed. init-code executed twice , 2 texttospeech instances created , 2 oninit()
's interleaved.
the reason init code beeing called twice unexpected:
i have set attribute android:launchmode="singletask"
activity , documentation says onnewintent()
, not oncreate()
if activity running. assumed, , seemed true, onnewintent()
instead oncreate()
in rare cases, e.g. after user changed timezone, onnewintent()
immedeately after , in add-on to oncreate()
. don't believe behavior intended.
android text-to-speech
Comments
Post a Comment