LifecycleCoroutineScope
public abstract class LifecycleCoroutineScope
CoroutineScope tied to a Lifecycle and Dispatchers.Main.immediate
This scope will be cancelled when the Lifecycle is destroyed.
This scope provides specialised versions of launch: launchWhenCreated, launchWhenStarted, launchWhenResumed
Summary
Public fields |
|
|---|---|
abstract @NonNull CoroutineContext |
|
Public methods |
|
|---|---|
final @NonNull Job |
launchWhenCreated(Launches and runs the given block when the |
final @NonNull Job |
launchWhenResumed(Launches and runs the given block when the |
final @NonNull Job |
launchWhenStarted(Launches and runs the given block when the |
Public fields
Public methods
launchWhenCreated
@NonNull
public final Job launchWhenCreated(
@NonNull SuspendFunction1<@NonNull CoroutineScope, Unit> block
)
Launches and runs the given block when the Lifecycle controlling this LifecycleCoroutineScope is at least in Lifecycle.State.CREATED state.
The returned Job will be cancelled when the Lifecycle is destroyed.
Caution: This API is not recommended to use as it can lead to wasted resources in some cases. Please, use the Lifecycle.repeatOnLifecycle API instead. This API will be removed in a future release.
| See also | |
|---|---|
whenCreated |
|
coroutineScope |
|
launchWhenResumed
@NonNull
public final Job launchWhenResumed(
@NonNull SuspendFunction1<@NonNull CoroutineScope, Unit> block
)
Launches and runs the given block when the Lifecycle controlling this LifecycleCoroutineScope is at least in Lifecycle.State.RESUMED state.
The returned Job will be cancelled when the Lifecycle is destroyed.
Caution: This API is not recommended to use as it can lead to wasted resources in some cases. Please, use the Lifecycle.repeatOnLifecycle API instead. This API will be removed in a future release.
| See also | |
|---|---|
whenResumed |
|
coroutineScope |
|
launchWhenStarted
@NonNull
public final Job launchWhenStarted(
@NonNull SuspendFunction1<@NonNull CoroutineScope, Unit> block
)
Launches and runs the given block when the Lifecycle controlling this LifecycleCoroutineScope is at least in Lifecycle.State.STARTED state.
The returned Job will be cancelled when the Lifecycle is destroyed.
Caution: This API is not recommended to use as it can lead to wasted resources in some cases. Please, use the Lifecycle.repeatOnLifecycle API instead. This API will be removed in a future release.
| See also | |
|---|---|
whenStarted |
|
coroutineScope |
|