From f88de024b8f51b8d161ff2b082070a00257a8545 Mon Sep 17 00:00:00 2001 From: Phillip Hsu Date: Sat, 17 Sep 2016 16:20:10 -0700 Subject: [PATCH] Write isForeground() method --- .../clock2/ChronometerNotificationService.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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()); }