Write isForeground() method

This commit is contained in:
Phillip Hsu 2016-09-17 16:20:10 -07:00
parent 3de8074511
commit f88de024b8

View File

@ -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());
}