LifecycleResumeEffect

Functions summary

Unit

This function is deprecated. LifecycleResumeEffect must provide one or more 'key' parameters that define the identity of the LifecycleResumeEffect and determine when its previous effect coroutine should be cancelled and a new effect launched for the new key.

Cmn
Unit

Schedule a pair of effects to run when the Lifecycle receives either a Lifecycle.Event.ON_RESUME or Lifecycle.Event.ON_PAUSE (or any new unique value of key1).

Cmn
Unit
@Composable
LifecycleResumeEffect(
    vararg keys: Any?,
    lifecycleOwner: LifecycleOwner,
    effects: LifecycleResumePauseEffectScope.() -> LifecyclePauseOrDisposeEffectResult
)

Schedule a pair of effects to run when the Lifecycle receives either a Lifecycle.Event.ON_RESUME or Lifecycle.Event.ON_PAUSE (or any new unique value of keys).

Cmn
Unit
@Composable
LifecycleResumeEffect(
    key1: Any?,
    key2: Any?,
    lifecycleOwner: LifecycleOwner,
    effects: LifecycleResumePauseEffectScope.() -> LifecyclePauseOrDisposeEffectResult
)

Schedule a pair of effects to run when the Lifecycle receives either a Lifecycle.Event.ON_RESUME or Lifecycle.Event.ON_PAUSE (or any new unique value of key1 or key2).

Cmn
Unit
@Composable
LifecycleResumeEffect(
    key1: Any?,
    key2: Any?,
    key3: Any?,
    lifecycleOwner: LifecycleOwner,
    effects: LifecycleResumePauseEffectScope.() -> LifecyclePauseOrDisposeEffectResult
)

Schedule a pair of effects to run when the Lifecycle receives either a Lifecycle.Event.ON_RESUME or Lifecycle.Event.ON_PAUSE (or any new unique value of key1 or key2 or key3).

Cmn

Functions

LifecycleResumeEffect

@Composable
fun LifecycleResumeEffect(
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    effects: LifecycleResumePauseEffectScope.() -> LifecyclePauseOrDisposeEffectResult
): Unit

It is an error to call LifecycleStartEffect without at least one key parameter.

This deprecated-error function shadows the varargs overload so that the varargs version is not used without key parameters.

LifecycleResumeEffect

@Composable
fun LifecycleResumeEffect(
    key1: Any?,
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    effects: LifecycleResumePauseEffectScope.() -> LifecyclePauseOrDisposeEffectResult
): Unit

Schedule a pair of effects to run when the Lifecycle receives either a Lifecycle.Event.ON_RESUME or Lifecycle.Event.ON_PAUSE (or any new unique value of key1). The ON_RESUME effect will be the body of the effects block and the ON_PAUSE effect will be within the (onPauseOrDispose clause)LifecycleResumePauseEffectScope.onPauseOrDispose:

LifecycleResumeEffect(lifecycleOwner) {
// add ON_RESUME effect here

onPauseOrDispose {
// add clean up for work kicked off in the ON_RESUME effect here
}
}
import androidx.compose.runtime.Composable
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LifecycleResumeEffect

@Composable
fun Analytics(dataAnalytics: DataAnalytics) {
    LifecycleResumeEffect(dataAnalytics) {
        val timeTracker = dataAnalytics.startTimeTracking()

        onPauseOrDispose { timeTracker.stopTimeTracking() }
    }

    // ...
}

A LifecycleResumeEffect must include an onPauseOrDispose clause as the final statement in its effects block. If your operation does not require an effect for both Lifecycle.Event.ON_RESUME and Lifecycle.Event.ON_PAUSE, a LifecycleEventEffect should be used instead.

A LifecycleResumeEffect's key is a value that defines the identity of the effect. If a key changes, the LifecycleResumeEffect must dispose its current effects and reset by calling effects again. Examples of keys include:

  • Observable objects that the effect subscribes to

  • Unique request parameters to an operation that must cancel and retry if those parameters change

This function uses a LifecycleEventObserver to listen for when LifecycleResumeEffect enters the composition and the effects will be launched when receiving a Lifecycle.Event.ON_RESUME or Lifecycle.Event.ON_PAUSE event, respectively. If the LifecycleResumeEffect leaves the composition prior to receiving an Lifecycle.Event.ON_PAUSE event, onPauseOrDispose will be called to clean up the work that was kicked off in the ON_RESUME effect.

This function should not be used to launch tasks in response to callback events by way of storing callback data as a Lifecycle.State in a MutableState. Instead, see currentStateAsState to obtain a State that may be used to launch jobs in response to state changes.

Parameters
key1: Any?

The unique value to trigger recomposition upon change

lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current

The lifecycle owner to attach an observer

effects: LifecycleResumePauseEffectScope.() -> LifecyclePauseOrDisposeEffectResult

The effects to be launched when we receive the respective event callbacks

LifecycleResumeEffect

@Composable
fun LifecycleResumeEffect(
    vararg keys: Any?,
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    effects: LifecycleResumePauseEffectScope.() -> LifecyclePauseOrDisposeEffectResult
): Unit

Schedule a pair of effects to run when the Lifecycle receives either a Lifecycle.Event.ON_RESUME or Lifecycle.Event.ON_PAUSE (or any new unique value of keys). The ON_RESUME effect will be the body of the effects block and the ON_PAUSE effect will be within the (onPauseOrDispose clause)LifecycleResumePauseEffectScope.onPauseOrDispose:

LifecycleResumeEffect(lifecycleOwner) {
// add ON_RESUME effect here

onPauseOrDispose {
// add clean up for work kicked off in the ON_RESUME effect here
}
}
import androidx.compose.runtime.Composable
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LifecycleResumeEffect

@Composable
fun Analytics(dataAnalytics: DataAnalytics) {
    LifecycleResumeEffect(dataAnalytics) {
        val timeTracker = dataAnalytics.startTimeTracking()

        onPauseOrDispose { timeTracker.stopTimeTracking() }
    }

    // ...
}

A LifecycleResumeEffect must include an onPauseOrDispose clause as the final statement in its effects block. If your operation does not require an effect for both Lifecycle.Event.ON_RESUME and Lifecycle.Event.ON_PAUSE, a LifecycleEventEffect should be used instead.

A LifecycleResumeEffect's key is a value that defines the identity of the effect. If a key changes, the LifecycleResumeEffect must dispose its current effects and reset by calling effects again. Examples of keys include:

  • Observable objects that the effect subscribes to

  • Unique request parameters to an operation that must cancel and retry if those parameters change

This function uses a LifecycleEventObserver to listen for when LifecycleResumeEffect enters the composition and the effects will be launched when receiving a Lifecycle.Event.ON_RESUME or Lifecycle.Event.ON_PAUSE event, respectively. If the LifecycleResumeEffect leaves the composition prior to receiving an Lifecycle.Event.ON_PAUSE event, onPauseOrDispose will be called to clean up the work that was kicked off in the ON_RESUME effect.

This function should not be used to launch tasks in response to callback events by way of storing callback data as a Lifecycle.State in a MutableState. Instead, see currentStateAsState to obtain a State that may be used to launch jobs in response to state changes.

Parameters
vararg keys: Any?

The unique values to trigger recomposition upon changes

lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current

The lifecycle owner to attach an observer

effects: LifecycleResumePauseEffectScope.() -> LifecyclePauseOrDisposeEffectResult

The effects to be launched when we receive the respective event callbacks

LifecycleResumeEffect

@Composable
fun LifecycleResumeEffect(
    key1: Any?,
    key2: Any?,
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    effects: LifecycleResumePauseEffectScope.() -> LifecyclePauseOrDisposeEffectResult
): Unit

Schedule a pair of effects to run when the Lifecycle receives either a Lifecycle.Event.ON_RESUME or Lifecycle.Event.ON_PAUSE (or any new unique value of key1 or key2). The ON_RESUME effect will be the body of the effects block and the ON_PAUSE effect will be within the (onPauseOrDispose clause)LifecycleResumePauseEffectScope.onPauseOrDispose:

LifecycleResumeEffect(lifecycleOwner) {
// add ON_RESUME effect here

onPauseOrDispose {
// add clean up for work kicked off in the ON_RESUME effect here
}
}
import androidx.compose.runtime.Composable
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LifecycleResumeEffect

@Composable
fun Analytics(dataAnalytics: DataAnalytics) {
    LifecycleResumeEffect(dataAnalytics) {
        val timeTracker = dataAnalytics.startTimeTracking()

        onPauseOrDispose { timeTracker.stopTimeTracking() }
    }

    // ...
}

A LifecycleResumeEffect must include an onPauseOrDispose clause as the final statement in its effects block. If your operation does not require an effect for both Lifecycle.Event.ON_RESUME and Lifecycle.Event.ON_PAUSE, a LifecycleEventEffect should be used instead.

A LifecycleResumeEffect's key is a value that defines the identity of the effect. If a key changes, the LifecycleResumeEffect must dispose its current effects and reset by calling effects again. Examples of keys include:

  • Observable objects that the effect subscribes to

  • Unique request parameters to an operation that must cancel and retry if those parameters change

This function uses a LifecycleEventObserver to listen for when LifecycleResumeEffect enters the composition and the effects will be launched when receiving a Lifecycle.Event.ON_RESUME or Lifecycle.Event.ON_PAUSE event, respectively. If the LifecycleResumeEffect leaves the composition prior to receiving an Lifecycle.Event.ON_PAUSE event, onPauseOrDispose will be called to clean up the work that was kicked off in the ON_RESUME effect.

This function should not be used to launch tasks in response to callback events by way of storing callback data as a Lifecycle.State in a MutableState. Instead, see currentStateAsState to obtain a State that may be used to launch jobs in response to state changes.

Parameters
key1: Any?

A unique value to trigger recomposition upon change

key2: Any?

A unique value to trigger recomposition upon change

lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current

The lifecycle owner to attach an observer

effects: LifecycleResumePauseEffectScope.() -> LifecyclePauseOrDisposeEffectResult

The effects to be launched when we receive the respective event callbacks

LifecycleResumeEffect

@Composable
fun LifecycleResumeEffect(
    key1: Any?,
    key2: Any?,
    key3: Any?,
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    effects: LifecycleResumePauseEffectScope.() -> LifecyclePauseOrDisposeEffectResult
): Unit

Schedule a pair of effects to run when the Lifecycle receives either a Lifecycle.Event.ON_RESUME or Lifecycle.Event.ON_PAUSE (or any new unique value of key1 or key2 or key3). The ON_RESUME effect will be the body of the effects block and the ON_PAUSE effect will be within the (onPauseOrDispose clause)LifecycleResumePauseEffectScope.onPauseOrDispose:

LifecycleResumeEffect(lifecycleOwner) {
// add ON_RESUME effect here

onPauseOrDispose {
// add clean up for work kicked off in the ON_RESUME effect here
}
}
import androidx.compose.runtime.Composable
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LifecycleResumeEffect

@Composable
fun Analytics(dataAnalytics: DataAnalytics) {
    LifecycleResumeEffect(dataAnalytics) {
        val timeTracker = dataAnalytics.startTimeTracking()

        onPauseOrDispose { timeTracker.stopTimeTracking() }
    }

    // ...
}

A LifecycleResumeEffect must include an onPauseOrDispose clause as the final statement in its effects block. If your operation does not require an effect for both Lifecycle.Event.ON_RESUME and Lifecycle.Event.ON_PAUSE, a LifecycleEventEffect should be used instead.

A LifecycleResumeEffect's key is a value that defines the identity of the effect. If a key changes, the LifecycleResumeEffect must dispose its current effects and reset by calling effects again. Examples of keys include:

  • Observable objects that the effect subscribes to

  • Unique request parameters to an operation that must cancel and retry if those parameters change

This function uses a LifecycleEventObserver to listen for when LifecycleResumeEffect enters the composition and the effects will be launched when receiving a Lifecycle.Event.ON_RESUME or Lifecycle.Event.ON_PAUSE event, respectively. If the LifecycleResumeEffect leaves the composition prior to receiving an Lifecycle.Event.ON_PAUSE event, onPauseOrDispose will be called to clean up the work that was kicked off in the ON_RESUME effect.

This function should not be used to launch tasks in response to callback events by way of storing callback data as a Lifecycle.State in a MutableState. Instead, see currentStateAsState to obtain a State that may be used to launch jobs in response to state changes.

Parameters
key1: Any?

A unique value to trigger recomposition upon change

key2: Any?

A unique value to trigger recomposition upon change

key3: Any?

A unique value to trigger recomposition upon change

lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current

The lifecycle owner to attach an observer

effects: LifecycleResumePauseEffectScope.() -> LifecyclePauseOrDisposeEffectResult

The effects to be launched when we receive the respective event callbacks