OSDN Git Service

Fix some copy-paste errors and acquire locks before launching the Activity.
authorPatrick Scott <phanna@android.com>
Wed, 19 Aug 2009 20:19:15 +0000 (16:19 -0400)
committerPatrick Scott <phanna@android.com>
Wed, 19 Aug 2009 20:32:48 +0000 (16:32 -0400)
Acquiring the locks before launching the Activity prevents some strange pausing
behavior in ActivityManager. If the screen is off, the ActivityManager attempts
to pause the Activity before resuming it.

src/com/android/alarmclock/AlarmAlert.java
src/com/android/alarmclock/AlarmReceiver.java

index 038521b..e78112d 100644 (file)
@@ -218,16 +218,15 @@ public class AlarmAlert extends Activity {
 
     @Override
     protected void onStart() {
-        super.onResume();
+        super.onStart();
         if (Log.LOGV) Log.v("AlarmAlert.onStart()");
-        // Acquire a separate lock for the screen to stay on. This is necessary
-        // to avoid flashing the keyguard when the screen is locked.
+        // Acquire a separate lock for the screen to stay on.
         AlarmAlertWakeLock.acquireScreenWakeLock(this);
     }
 
     @Override
     protected void onStop() {
-        super.onPause();
+        super.onStop();
         if (Log.LOGV) Log.v("AlarmAlert.onStop()");
         AlarmAlertWakeLock.releaseScreenLock();
     }
index 7844283..7fc5b35 100644 (file)
@@ -88,6 +88,14 @@ public class AlarmReceiver extends BroadcastReceiver {
             return;
         }
 
+        // Maintain a cpu wake lock until the AlarmAlert and AlarmKlaxon can
+        // pick it up. Also acquire the screen lock so the screen is on before
+        // starting the AlarmAlert activity. Do this before launching the
+        // AlarmAlert so that the ActivityManager does not try to pause the
+        // activity due to the screen being off.
+        AlarmAlertWakeLock.acquireCpuWakeLock(context);
+        AlarmAlertWakeLock.acquireScreenWakeLock(context);
+
         /* Close dialogs and window shade */
         Intent closeDialogs = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
         context.sendBroadcast(closeDialogs);
@@ -154,10 +162,6 @@ public class AlarmReceiver extends BroadcastReceiver {
         // correct notification.
         NotificationManager nm = getNotificationManager(context);
         nm.notify(alarm.id, n);
-
-        // Maintain a cpu wake lock until the AlarmAlert and AlarmKlaxon can
-        // pick it up.
-        AlarmAlertWakeLock.acquireCpuWakeLock(context);
     }
 
     private NotificationManager getNotificationManager(Context context) {