From the BroadcastReceiver I want to call a activity without graphic. Without graphic because it will speak some words.
Intent iSpeechIntent = new Intent(context, TTS.class);
iSpeechIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(iSpeechIntent);
but activity cycle is not finished correctly. onDestroy() method is never executed. Why?
@Override
public void onDestroy() {
// Don't forget to shutdown!
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
And is OK if i am using activity without graphic XML just for speak some text with TTSEngine?
You misunderstood Activity lifecycle.
onDestroy()is NOT called when your activity is dismissed. And dismissing it (i.e. by starting another activity) does NOT equal destroying activity (however you may enforce destroy of activity, by callingfinish()– and then youronDestroy()method will be invoked). You may want to move your code toonPause()andonResume()respectively or maybe you shall use IntentService instead, if you dot require any UI for the task.