Fixed active alarm notification dismiss bug found in RingtoneService

This commit is contained in:
Phillip Hsu 2016-06-07 19:58:41 -07:00
parent abdb939ada
commit ffb6f40fd0
2 changed files with 15 additions and 10 deletions

View File

@ -132,7 +132,7 @@ public class RingtoneActivity extends AppCompatActivity implements RingtoneServi
private void snooze() { private void snooze() {
AlarmUtils.snoozeAlarm(this, mAlarm); AlarmUtils.snoozeAlarm(this, mAlarm);
// Can't call dismiss() because we don't want to also call cancelAlarm()! Why? For example, // Can't call dismiss() because we don't want to also call cancelAlarm()! Why? For example,
// we don't want the alarm, if it has no recurrence, to be turned off immediately. // we don't want the alarm, if it has no recurrence, to be turned off right now.
unbindService(); // don't wait for finish() to call onDestroy() unbindService(); // don't wait for finish() to call onDestroy()
finish(); finish();
} }

View File

@ -77,19 +77,24 @@ public class RingtoneService extends Service { // TODO: abstract this, make subc
// stopService(Intent) [or stopSelf()] is called, regardless of whether any clients are connected to it." // stopService(Intent) [or stopSelf()] is called, regardless of whether any clients are connected to it."
// I have found the regardless part does not apply here. You MUST also unbind any clients from this service // I have found the regardless part does not apply here. You MUST also unbind any clients from this service
// at the same time you stop this service! // at the same time you stop this service!
long id = intent.getLongExtra(EXTRA_ITEM_ID, -1); String action = intent.getAction();
if (id < 0) if (!action.equals(ACTION_SNOOZE) && !action.equals(ACTION_DISMISS))
throw new IllegalStateException("No item id set"); throw new UnsupportedOperationException();
Alarm alarm = checkNotNull(AlarmsRepository.getInstance(this).getItem(id));
if (ACTION_SNOOZE.equals(intent.getAction())) { if (ACTION_SNOOZE.equals(intent.getAction())) {
long id = intent.getLongExtra(EXTRA_ITEM_ID, -1);
if (id < 0)
throw new IllegalStateException("No item id set");
Alarm alarm = checkNotNull(AlarmsRepository.getInstance(this).getItem(id));
AlarmUtils.snoozeAlarm(this, alarm); AlarmUtils.snoozeAlarm(this, alarm);
} else if (ACTION_DISMISS.equals(intent.getAction())) {
AlarmUtils.cancelAlarm(this, alarm);
} else {
throw new UnsupportedOperationException();
} }
// ============================== WARNING ===================================
// DO NOT DO ANYTHING FOR ACTION_DISMISS. RingtoneActivity's current implementation of
// onServiceFinish() calls cancelAlarm for you!
// /*else if (ACTION_DISMISS.equals(intent.getAction())) {
// AlarmUtils.cancelAlarm(this, alarm);
// }*/
// ==========================================================================
stopSelf(startId); stopSelf(startId);
if (mRingtoneCallback != null) { if (mRingtoneCallback != null) {
mRingtoneCallback.onServiceFinish(); // tell client to unbind from this service mRingtoneCallback.onServiceFinish(); // tell client to unbind from this service