Here are couple of useful links for you to get started:
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
// Call this method directly from java file | |
int secs = 2; // Delay in seconds | |
Utils.delay(secs, new Utils.DelayCallback() { | |
@Override | |
public void afterDelay() { | |
// Do something after delay | |
} |
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
package com.example.data; | |
import java.util.ArrayList; | |
public class DummyData { | |
/** | |
* An {@link ArrayList} to store data. | |
*/ | |
private static ArrayList<Model> mData; |
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
class NetworkWorker(private val context: Context, private val params: WorkerParameters) : Worker(context, params) { | |
override fun doWork(): Result { | |
// Get the input data | |
val userData = params.inputData.getStringArray(KEY_USER_DATA) | |
val secretKey = params.inputData.getString(KEY_SECRET_KEY) | |
secretKey ?: run { | |
Log.e(TAG, "doWork: SecretKey not found in WorkParams") |
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 buildPeriodicRequest(secretKey: String, userData: Array<String>): PeriodicWorkRequest { | |
val inputData = Data.Builder() | |
.putString(KEY_SECRET_KEY, secretKey) | |
.putStringArray(KEY_USER_DATA, userData) | |
.build() | |
val constraints = Constraints.Builder() | |
.setRequiredNetworkType(NetworkType.CONNECTED) | |
.setRequiresCharging(true).build() |
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
class SimpleWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) { | |
private val delayInSeconds: Int = workerParams.inputData.getInt(KEY_DELAY, 0) | |
override fun doWork(): Result { | |
// Do intensive task here | |
// For now, our old friend Thread.sleep can replace intensive task here. | |
Thread.sleep(delayInSeconds * 1000L) | |
// Return with success |
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
val inputData: Data = Data.Builder().putInt(SimpleWorker.KEY_DELAY, 5).build() | |
val simpleWorkRequest = OneTimeWorkRequest.Builder(SimpleWorker::class.java) | |
.setInputData(inputData) | |
.build() | |
WorkManager.getInstance().enqueue(simpleWorkRequest) |
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
val workerId = simpleWorkRequest.id | |
WorkManager.getInstance().getWorkInfoByIdLiveData(workerId) | |
.observe(this, Observer<WorkInfo> { | |
it?.let { workInfo -> | |
when (workInfo.state) { | |
WorkInfo.State.ENQUEUED -> | |
Log.d(TAG, "Worker ENQUEUED") | |
WorkInfo.State.RUNNING -> | |
Log.d(TAG, "Worker RUNNING") |
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
{ | |
"200":{ | |
"icon":"thunderstorm", | |
"icon-day":"day-thunderstorm", | |
"icon-night":"night-alt-thunderstorm" | |
}, | |
"201":{ | |
"icon":"thunderstorm", | |
"icon-day":"day-thunderstorm", | |
"icon-night":"night-alt-thunderstorm" |