bookmate game
en

Mark Murphy

  • b4777467766fez uma citaçãohá 2 anos
    implementations of LifecycleOwner offer a lifecycleScope extension property.
  • b4777467766fez uma citaçãohá 2 anos
    When the owner advances to a destroyed state, the CoroutineScope is canceled.
  • b4777467766fez uma citaçãohá 2 anos
    ...() functions on Lifecycle:

    whenCreated()
    whenStarted()
    whenResumed()
    whenStateAtLeast()
  • b4777467766fez uma citaçãohá 2 anos
    The idea is that you can arrange to do work when particular lifecycle events occur, and you can launch coroutines or consume flows and channels as part of that processing. The CoroutineScope used for the lambda expression is the same basic scope as lifecycleScope gives you, so it will be canceled once the associated Lifecycle is destroyed. It will also be canceled once the lifecycle leaves the requested state — whenResumed(), for example, will be canceled once the lifecycle leaves the resumed state (e.g., after onPause() is called on the activity/fragment).
  • b4777467766fez uma citaçãohá 2 anos
    The documentation for whenStateAtLeast() lists a bunch of limitations. A key one is that exception handlers (catch and finally) might be executed after the Lifecycle is destroyed, so it may not be safe to update the UI from there.
  • b4777467766fez uma citaçãohá 2 anos
    There are equivalent coroutine builders on the lifecycleScope, filling the same role with slightly different syntax:

    launchWhenCreated()
    launchWhenStarted()
    launchWhenResumed()
  • b4777467766fez uma citaçãohá 2 anos
    The scopes supplied by the Jetpack libraries — viewModelScope and lifecycleScope among them — do not use Dispatchers.Default as the default dispatcher. Instead, they use Dispatchers.Main.immediate as the default.
  • b4777467766fez uma citaçãohá 2 anos
    StateFlow was added in version 1.3.6 of the coroutines library. It is the long-term option for handling LiveData-style scenarios.
  • b4777467766fez uma citaçãohá 2 anos
    sometimes, we want to do something exactly once, as the “something” has its own lifecycle and handles configuration changes on its own.
  • b4777467766fez uma citaçãohá 2 anos
    Nowadays, Google engineers are steering us away from the single-live-event pattern and to… well, frankly, just about anything else for events. And, in the coroutines space, “just about anything else” is a Channel.
fb2epub
Arraste e solte seus arquivos (não mais do que 5 por vez)