Created
September 11, 2018 14:59
-
-
Save adriantache/21c7b30d7c501b4ef5985309ba33053c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//firstly, we create a new piece of LiveData to pass the remote URL to the | |
// Worker, and for that we define the REMOTE_URL String and initialize it | |
// by calling the getRemoteURL() method in our app | |
Data remoteUrl = new Data.Builder().putString(REMOTE_URL, getRemoteURL()).build(); | |
//then, we create a new OneTimeWorkRequest since we don't need it to be | |
//periodic, and set InputData to what we defined above, and add a work | |
//tag just in case we want to cancel this work | |
OneTimeWorkRequest getEventJson = new OneTimeWorkRequest | |
.Builder(UpdateEventsWorker.class) | |
.setInputData(remoteUrl) | |
.addTag(EVENTS_JSON_WORK_TAG) | |
.build(); | |
//finally, we enqueue the work, letting WorkManager decide when it runs, | |
//but it is currently set up so it runs as soon as possible | |
WorkManager.getInstance().enqueue(getEventJson); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment