LifecycleStartEffect

Functions summary

Unit

This function is deprecated. LifecycleStartEffect must provide one or more 'key' parameters that define the identity of the LifecycleStartEffect 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_START or Lifecycle.Event.ON_STOP (or any new unique value of key1).

Cmn
Unit
@Composable
LifecycleStartEffect(
    vararg keys: Any?,
    lifecycleOwner: LifecycleOwner,
    effects: LifecycleStartStopEffectScope.() -> LifecycleStopOrDisposeEffectResult
)

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

Cmn
Unit
@Composable
LifecycleStartEffect(
    key1: Any?,
    key2: Any?,
    lifecycleOwner: LifecycleOwner,
    effects: LifecycleStartStopEffectScope.() -> LifecycleStopOrDisposeEffectResult
)

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

Cmn
Unit
@Composable
LifecycleStartEffect(
    key1: Any?,
    key2: Any?,
    key3: Any?,
    lifecycleOwner: LifecycleOwner,
    effects: LifecycleStartStopEffectScope.() -> LifecycleStopOrDisposeEffectResult
)

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

Cmn

Functions

LifecycleStartEffect

@Composable
fun LifecycleStartEffect(
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    effects: LifecycleStartStopEffectScope.() -> LifecycleStopOrDisposeEffectResult
): 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.

LifecycleStartEffect

@Composable
fun LifecycleStartEffect(
    key1: Any?,
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    effects: LifecycleStartStopEffectScope.() -> LifecycleStopOrDisposeEffectResult
): Unit

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

LifecycleStartEffect(lifecycleOwner) {
// add ON_START effect here

onStopOrDispose {
// add clean up for work kicked off in the ON_START effect here
}
}
import androidx.compose.runtime.Composable
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LifecycleStartEffect

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

        onStopOrDispose { timeTracker.stopTimeTracking() }
    }

    // ...
}

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

A LifecycleStartEffect's key is a value that defines the identity of the effect. If the key changes, the LifecycleStartEffect 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 LifecycleStartEffect enters the composition and the effects will be launched when receiving a Lifecycle.Event.ON_START or Lifecycle.Event.ON_STOP event, respectively. If the LifecycleStartEffect leaves the composition prior to receiving an Lifecycle.Event.ON_STOP event, onStopOrDispose will be called to clean up the work that was kicked off in the ON_START 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: LifecycleStartStopEffectScope.() -> LifecycleStopOrDisposeEffectResult

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

LifecycleStartEffect

@Composable
fun LifecycleStartEffect(
    vararg keys: Any?,
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    effects: LifecycleStartStopEffectScope.() -> LifecycleStopOrDisposeEffectResult
): Unit

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

LifecycleStartEffect(lifecycleOwner) {
// add ON_START effect here

onStopOrDispose {
// add clean up for work kicked off in the ON_START effect here
}
}
import androidx.compose.runtime.Composable
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LifecycleStartEffect

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

        onStopOrDispose { timeTracker.stopTimeTracking() }
    }

    // ...
}

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

A LifecycleStartEffect's key is a value that defines the identity of the effect. If a key changes, the LifecycleStartEffect 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 LifecycleStartEffect enters the composition and the effects will be launched when receiving a Lifecycle.Event.ON_START or Lifecycle.Event.ON_STOP event, respectively. If the LifecycleStartEffect leaves the composition prior to receiving an Lifecycle.Event.ON_STOP event, onStopOrDispose will be called to clean up the work that was kicked off in the ON_START 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: LifecycleStartStopEffectScope.() -> LifecycleStopOrDisposeEffectResult

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

LifecycleStartEffect

@Composable
fun LifecycleStartEffect(
    key1: Any?,
    key2: Any?,
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    effects: LifecycleStartStopEffectScope.() -> LifecycleStopOrDisposeEffectResult
): Unit

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

LifecycleStartEffect(lifecycleOwner) {
// add ON_START effect here

onStopOrDispose {
// add clean up for work kicked off in the ON_START effect here
}
}
import androidx.compose.runtime.Composable
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LifecycleStartEffect

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

        onStopOrDispose { timeTracker.stopTimeTracking() }
    }

    // ...
}

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

A LifecycleStartEffect's key is a value that defines the identity of the effect. If a key changes, the LifecycleStartEffect 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 LifecycleStartEffect enters the composition and the effects will be launched when receiving a Lifecycle.Event.ON_START or Lifecycle.Event.ON_STOP event, respectively. If the LifecycleStartEffect leaves the composition prior to receiving an Lifecycle.Event.ON_STOP event, onStopOrDispose will be called to clean up the work that was kicked off in the ON_START 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: LifecycleStartStopEffectScope.() -> LifecycleStopOrDisposeEffectResult

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

LifecycleStartEffect

@Composable
fun LifecycleStartEffect(
    key1: Any?,
    key2: Any?,
    key3: Any?,
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    effects: LifecycleStartStopEffectScope.() -> LifecycleStopOrDisposeEffectResult
): Unit

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

LifecycleStartEffect(lifecycleOwner) {
// add ON_START effect here

onStopOrDispose {
// add clean up for work kicked off in the ON_START effect here
}
}
import androidx.compose.runtime.Composable
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LifecycleStartEffect

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

        onStopOrDispose { timeTracker.stopTimeTracking() }
    }

    // ...
}

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

A LifecycleStartEffect's key is a value that defines the identity of the effect. If a key changes, the LifecycleStartEffect 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 LifecycleStartEffect enters the composition and the effects will be launched when receiving a Lifecycle.Event.ON_START or Lifecycle.Event.ON_STOP event, respectively. If the LifecycleStartEffect leaves the composition prior to receiving an Lifecycle.Event.ON_STOP event, onStopOrDispose will be called to clean up the work that was kicked off in the ON_START 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

key2: Any?

The unique value to trigger recomposition upon change

key3: Any?

The unique value to trigger recomposition upon change

lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current

The lifecycle owner to attach an observer

effects: LifecycleStartStopEffectScope.() -> LifecycleStopOrDisposeEffectResult

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