Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

07-workmanager #14

Open
wants to merge 1 commit into
base: 06-navigation
Choose a base branch
from
Open

07-workmanager #14

wants to merge 1 commit into from

Conversation

Serchinastico
Copy link
Contributor

This PR is not meant to be merged

This is how to use the WorkManager component:

  • Create a Worker. It might be a synchronous Worker that is going to be executed in a background thread or an asynchronous ListenableWorker that runs in the UI thread and returns a ListenableFuture. We opted for a regular Worker because we didn't have any asynchronous computation.
  • Register a PeriodicWorkRequest on the Application::onCreate method that runs every 15 minutes (the minimum period for workers). It deletes half the super heroes from the list.
  • Create a test for the worker + Room. I'm going to move the Room test to 02c-room-testing and here I will be just moving it to a worker test to see how to write them. The hardest part was to get deterministic results. Workers were being executed a random number of times even though I'm enqueuing it only once. The solution is to enqueue the worker on the UI thread with getInstrumentation().runOnMainSync but I'm still unsure why this fixes anything 🤷‍♂️.

Copy link
Member

@davideme davideme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job

@Serchinastico Serchinastico force-pushed the 07-workmanager branch 2 times, most recently from 69c1fae to bda0424 Compare March 15, 2019 11:42
@Serchinastico Serchinastico force-pushed the 06-navigation branch 2 times, most recently from f6c7309 to c76a270 Compare March 15, 2019 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants