Write isForeground() method
This commit is contained in:
parent
3de8074511
commit
f88de024b8
@ -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());
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user