Skip to content

Instantly share code, notes, and snippets.

@adriantache
Created September 11, 2018 14:59
Show Gist options
  • Save adriantache/21c7b30d7c501b4ef5985309ba33053c to your computer and use it in GitHub Desktop.
Save adriantache/21c7b30d7c501b4ef5985309ba33053c to your computer and use it in GitHub Desktop.
//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