May 2022
Intermediate to advanced
688 pages
20h 12m
English
Some users may not want your app to run in the background. An important control to provide users is the ability to enable and disable background polling.
For PhotoGallery, you will add a menu item to the app bar that will toggle your worker when selected. You will also update your work request to run your worker periodically instead of just once.
To toggle your worker, you first need to determine whether the worker is currently running. To do this, supplement your PreferencesRepository to store a flag indicating whether the worker is enabled.
Listing 22.12 Saving Worker state (PreferencesRepository.kt)
class PreferencesRepository private constructor( private val dataStore: DataStore<Preferences> ...
Read now
Unlock full access