Skip to content

Instantly share code, notes, and snippets.

Avatar

Magda Miu magdamiu

View GitHub Profile
@magdamiu
magdamiu / build.gradle
Created Jul 4, 2019
Add google() repository in order to use WorkManager
View build.gradle
allprojects {
repositories {
google()
jcenter()
}
}
@magdamiu
magdamiu / WorkManagerExample.kt
Created Jul 4, 2019
Apply Constraints on the task
View WorkManagerExample.kt
val constraints = Constraints.Builder()
.setRequiresCharging(true)
.setRequiresStorageNotLow(true)
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
val syncOnlyOnce = OneTimeWorkRequestBuilder<SyncDataWorker>()
.setConstraints(constraints)
.build()
@magdamiu
magdamiu / WorkManagerExample.kt
Created Jul 4, 2019
Input and output data for a task
View WorkManagerExample.kt
val userIdData = Data.Builder()
.putInt(DATA_USER_ID, userId)
.build()
val syncOnlyOnce = OneTimeWorkRequestBuilder<SyncWorker>()
.setInputData(userIdData)
.build()
val userIdInput = inputData.getInt(Constants.DATA_USER_ID, 0)
View WorkManagerExample.kt
val syncOnlyOnce = OneTimeWorkRequestBuilder<SyncWorker>()
.setInputData(userIdData)
.addTag(Constants.WORKER_SYNC)
.addTag(Constants.ONE_SYNC)
.build()
View WorkManagerExample.kt
WorkManager.getInstance()
.beginUniqueWork(Constants.UNIQUE_NAME, ExistingWorkPolicy.REPLACE, task1)
.then(task2)
.then(task3)
.enqueue()
View WorkManagerExample.kt
WorkManager.getInstance()
.beginUniqueWork(Constants.UNIQUE_NAME, ExistingWorkPolicy.REPLACE, task1)
.then(task2)
.then(task3)
.enqueue()
View WorkManagerExample.kt
WorkManager.getInstance()
.beginUniqueWork(Constants.UNIQUE_NAME, ExistingWorkPolicy.REPLACE, task1)
.then(task2)
.then(task3)
.enqueue()
View WorkManagerExample.kt
WorkManager.getInstance()
.beginUniqueWork(Constants.UNIQUE_NAME, ExistingWorkPolicy.REPLACE, task1)
.then(task2)
.then(task3)
.enqueue()
View WorkManagerExample.kt
WorkManager.getInstance()
.beginUniqueWork(Constants.UNIQUE_NAME, ExistingWorkPolicy.REPLACE, task1)
.then(task2)
.then(task3)
.enqueue()
View WorkManagerExample.kt
WorkManager.getInstance()
.beginUniqueWork(Constants.UNIQUE_NAME, ExistingWorkPolicy.REPLACE, task1)
.then(task2)
.then(task3)
.enqueue()