can I always use WorkManager instead of coroutines?

后端 未结 5 1654
没有蜡笔的小新
没有蜡笔的小新 2021-02-09 01:53

I wonder why should I bother with rx or coroutines when there is brilliant solution as WorkManager. But for almost all tutorials they use coroutines so may be WorkManager has di

5条回答
  •  再見小時候
    2021-02-09 02:09

    Background tasks fall into one of the following main categories:

    1. Immediate
    2. Deferred
    3. Exact

    To categorize a task, answer the following questions:

    Does the task need to complete while the user is interacting with the application?

    If so, this task should be categorized for immediate execution. If not, proceed to the second question.

    Does the task need to run at an exact time?

    If you do need to run a task at an exact time, categorize the task as exact.

    Most tasks don't need to be run at an exact time. Tasks generally allow for slight variations in when they run that are based on conditions such as network availability and remaining battery. Tasks that don't need to be run at an exact time should be categorized as deferred.

    Use Kotlin Coroutine when a task needs to execute immediately and if the task will end when the user leaves a certain scope or finishes an interaction.

    Use WorkManager when a task needs to execute immediately and need continued processing, even if the user puts the application in the background or the device restarts

    Use AlarmManager when a task that needs to be executed at an exact point in time

    For more details, visit this link

提交回复
热议问题