LifecycleCoroutineScope


public abstract class LifecycleCoroutineScope implements CoroutineScope


CoroutineScope tied to a Lifecycle and Dispatchers.Main.immediate

This scope will be cancelled when the Lifecycle is destroyed.

Summary

Public methods

final @NonNull Job

This method is deprecated. launchWhenCreated is deprecated as it can lead to wasted resources in some cases.

final @NonNull Job

This method is deprecated. launchWhenResumed is deprecated as it can lead to wasted resources in some cases.

final @NonNull Job

This method is deprecated. launchWhenStarted is deprecated as it can lead to wasted resources in some cases.

Public methods

launchWhenCreated

Added in 2.2.0
public final @NonNull Job launchWhenCreated(
    @ExtensionFunctionType @NonNull SuspendFunction1<@NonNull CoroutineScopeUnit> 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.

launchWhenResumed

Added in 2.2.0
public final @NonNull Job launchWhenResumed(
    @ExtensionFunctionType @NonNull SuspendFunction1<@NonNull CoroutineScopeUnit> 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.

launchWhenStarted

Added in 2.2.0
public final @NonNull Job launchWhenStarted(
    @ExtensionFunctionType @NonNull SuspendFunction1<@NonNull CoroutineScopeUnit> 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.