Last active
February 23, 2021 15:27
-
-
Save rotman/cddf12de1e4c7fa774215af750dfe82e to your computer and use it in GitHub Desktop.
Create and schedule foreground task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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