Step #8: Trying It Out

Start by clearing out all to-do items, deleting them one at a time or uninstalling and reinstalling the app. This will help make it easier for you to see the results.

If you run the app and tap on the “Settings” overflow menu item, you will see our two preferences. In the previous tutorial, we had you temporarily put a bad URL in the “Web service URL” preference — if you did not fix that, do so now.

Then, toggle the “Import periodically” switch to the on position, and use back navigation to return to the to-do roster. You should see imported to-do items, as WorkManager will do our work immediately, then again every 15 minutes (or thereabouts).

If you delete the imported items, exit out of the app, and return to the app later, if enough time elapsed and you had an Internet connection, you should see the imported items again, as our ImportWorker was asked to do its work again.

At this point, go back into “Settings” and uncheck the SwitchPreference, as you really do not need to be making lots of requests for the same set of to-do items. In a real app and a real Web service, the mix of to-do items might be changing (e.g., the user used a desktop Web browser to add or remove items), and so importing every so often might make sense.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.