Skip to content

Instantly share code, notes, and snippets.

@rotman
Last active February 23, 2021 15:27
Show Gist options
  • Save rotman/cddf12de1e4c7fa774215af750dfe82e to your computer and use it in GitHub Desktop.
Save rotman/cddf12de1e4c7fa774215af750dfe82e to your computer and use it in GitHub Desktop.
Create and schedule foreground task
fun scheduleForegroundTask() {
val foregroundTaskInfo = foregroundTaskInfo {
id = TASK_ID
networkType = NetworkType.Any
persisted = true
minLatencyMillis = TimeUnit.HOURS.toMillis(12)
timeoutMillis = TimeUnit.MINUTES.toMillis(1)
retryData = RetryData(retryPolicy = RetryPolicy.Exponential, initialBackoff = 4000)
}
ForegroundTasksSchedulerWrapper().scheduleForegroundTask(
ReposForegroundService::class.java,
foregroundTaskInfo
)
}
fun cancelForegroundTask() {
ForegroundTasksSchedulerWrapper().cancel(TASK_ID)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment