Reputation:
I am reading about WorkManager (https://developer.android.com/guide/background). What confuses me are the 2 conflicting statements. It says WorkManager should be used:
Can someone explain this and show me 2 simple examples with the code of WorkManger that does statement number1 and statement number2 situations. Thanks
Upvotes: 3
Views: 1985
Reputation: 12953
WorkManager
is basically to offload work from your Process/Activity to dedicated worker meaning your app doesn't need to be active for WorkManager to do your work.
The above mentioned both statements makes sense, I won't be writing code but i'll mention use cases supporting two statements.
Statement1 says tasks which should be executed immediately and need continued processing, it means you can schedule any task right away and will be long running, for instance consider you are uploading some images on click of a button, so you will start the UploadWorker as soon as user clicks upload(instantly) and even if user kills your App, upload should still happen which will be taken care by WorkManager.
Statement2 says tasks that can run at any time in the future can be and deferred, it means you can schedule some work in future point of time and WorkManager will run it at your desired time. A typical example would be backups, you want to back up user data every day at morning, then you can create a BackUpWorker and ask WorkManager to run it at a future time periodically.
Upvotes: 3