From: Daniel Sandler Date: Mon, 15 Mar 2010 21:05:03 +0000 (-0400) Subject: Keep listening for dock event broadcasts when paused. X-Git-Tag: android-x86-2.2~16 X-Git-Url: http://git.sourceforge.jp/view?p=android-x86%2Fpackages-apps-DeskClock.git;a=commitdiff_plain;h=3f5052618fc262c22b9e00137014329bcc660524 Keep listening for dock event broadcasts when paused. When the screen is off, the dock app is paused; if the device is undocked in this state, there's a race to resume the dock app & broadcast the UI mode change event. Fixed. Bug: 2507444 Change-Id: I7416aed4f9def0b9458273f40fe27131412d23f0 --- diff --git a/src/com/android/deskclock/DeskClock.java b/src/com/android/deskclock/DeskClock.java index f15bec2..09b7bb7 100644 --- a/src/com/android/deskclock/DeskClock.java +++ b/src/com/android/deskclock/DeskClock.java @@ -559,13 +559,8 @@ public class DeskClock extends Activity { } @Override - public void onResume() { - super.onResume(); - if (DEBUG) Log.d(LOG_TAG, "onResume with intent: " + getIntent()); - - // reload the date format in case the user has changed settings - // recently - mDateFormat = getString(R.string.full_wday_month_day_no_year); + public void onStart() { + super.onStart(); IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_DATE_CHANGED); @@ -573,6 +568,23 @@ public class DeskClock extends Activity { filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); filter.addAction(ACTION_MIDNIGHT); registerReceiver(mIntentReceiver, filter); + } + + @Override + public void onStop() { + super.onStop(); + + unregisterReceiver(mIntentReceiver); + } + + @Override + public void onResume() { + super.onResume(); + if (DEBUG) Log.d(LOG_TAG, "onResume with intent: " + getIntent()); + + // reload the date format in case the user has changed settings + // recently + mDateFormat = getString(R.string.full_wday_month_day_no_year); // Listen for updates to weather data Uri weatherNotificationUri = new Uri.Builder() @@ -635,7 +647,8 @@ public class DeskClock extends Activity { restoreScreen(); // Other things we don't want to be doing in the background. - unregisterReceiver(mIntentReceiver); + // NB: we need to keep our broadcast receiver alive in case the dock + // is disconnected while the screen is off getContentResolver().unregisterContentObserver(mContentObserver); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);