Initialize voiceDialer in onCreate instead of onStart
Bug: 5234283
Apparently in Honeycomb, a change was made so that
an onscreen activity would be stopped when the screen
turned off. This was not the case in prior releases.
The VoiceDialerActivity was initializing the TTS
engine and recognizer engine in onStart(), and
tearing everything down in onStop(), which means
that post Honeycomb, it doesn't work if the screen is off.
Now, it initializes everything in onCreate() and
tears it down in onDestroy().
It would be much better if all of the connections to
the TTS engine and bluetooth, along with the state
control, were kept in a service. This way the activity
could be dumb, and it could be destroyed and recreated
without losing state. That's far too big of a change for
ICS at this point though.
Change-Id: Id27996cc64f919061f0c513660837f6dff53d467
diff --git a/src/com/android/voicedialer/VoiceDialerActivity.java b/src/com/android/voicedialer/VoiceDialerActivity.java
index c6ac216..ea80e2c 100644
--- a/src/com/android/voicedialer/VoiceDialerActivity.java
+++ b/src/com/android/voicedialer/VoiceDialerActivity.java
@@ -183,17 +183,18 @@
@Override
protected void onCreate(Bundle icicle) {
- if (false) Log.d(TAG, "onCreate");
super.onCreate(icicle);
+ // TODO: All of this state management and holding of
+ // connections to the TTS engine and recognizer really
+ // belongs in a service. The activity can be stopped or deleted
+ // and recreated for lots of reasons.
+ // It's way too late in the ICS release cycle for a change
+ // like this now though.
+ // MHibdon Sept 20 2011
mHandler = new Handler();
mAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
mToneGenerator = new ToneGenerator(AudioManager.STREAM_RING,
ToneGenerator.MAX_VOLUME);
- }
-
- protected void onStart() {
- if (false) Log.d(TAG, "onStart " + getIntent());
- super.onStart();
acquireWakeLock(this);
@@ -1098,9 +1099,7 @@
return msecDelay;
}
- protected void onStop() {
- if (false) Log.d(TAG, "onStop");
-
+ protected void onDestroy() {
synchronized(this) {
mState = EXITING;
}
@@ -1143,19 +1142,16 @@
}
unregisterReceiver(mReceiver);
- super.onStop();
+ super.onDestroy();
releaseWakeLock();
-
- // It makes no sense to have this activity maintain state when in
- // background. When it stops, it should just be destroyed.
- finish();
}
private void acquireWakeLock(Context context) {
if (mWakeLock == null) {
PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
- mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "VoiceDialer");
+ mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
+ "VoiceDialer");
mWakeLock.acquire();
}
}
@@ -1177,10 +1173,4 @@
mHandler.postDelayed(this, 750);
}
};
-
- @Override
- protected void onDestroy() {
- if (false) Log.d(TAG, "onDestroy");
- super.onDestroy();
- }
}