diff --git a/app/src/main/java/com/philliphsu/clock2/ChronometerNotificationService.java b/app/src/main/java/com/philliphsu/clock2/ChronometerNotificationService.java index 86e9c00..c88e873 100644 --- a/app/src/main/java/com/philliphsu/clock2/ChronometerNotificationService.java +++ b/app/src/main/java/com/philliphsu/clock2/ChronometerNotificationService.java @@ -45,10 +45,18 @@ public abstract class ChronometerNotificationService extends Service { protected abstract boolean isCountDown(); /** - * @return the id for the foreground notification + * @return the id for the foreground notification, if {@link #isForeground()} returns true. + * Otherwise, this value will not be considered for anything. */ protected abstract int getNoteId(); + /** + * @return whether this service should run in the foreground. The default is true. + */ + protected boolean isForeground() { + return true; + } + /** * The intent received in {@link #onStartCommand(Intent, int, int)} * has no {@link Intent#getAction() action} set. At this point, you @@ -80,7 +88,9 @@ public abstract class ChronometerNotificationService extends Service { .setShowWhen(false) .setOngoing(true) .setContentIntent(getContentIntent()); - startForeground(getNoteId(), mNoteBuilder.build()); + if (isForeground()) { + startForeground(getNoteId(), mNoteBuilder.build()); + } mDelegate.init(); mDelegate.setCountDown(isCountDown()); }