dropUnlessResumed

Functions summary

() -> Unit
@Composable
dropUnlessResumed(lifecycleOwner: LifecycleOwner, block: () -> Unit)

Returns a new decorated function that will invoke the given block if the lifecycleOwner 's lifecycle state is at least State.RESUMED .

Cmn

Functions

dropUnlessResumed

@Composable 
fun dropUnlessResumed(
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
block: () -> Unit
): () -> Unit

Returns a new decorated function that will invoke the given block if the lifecycleOwner 's lifecycle state is at least State.RESUMED . Otherwise, block is not invoked.

For Navigation users, it's recommended to safeguard navigate methods when using them while a composable is in transition as a result of navigation.

importandroidx.compose.material.Button
importandroidx.compose.material.Text
importandroidx.lifecycle.compose.dropUnlessResumed
Button(
onClick=
dropUnlessResumed{
// Run on clicks only when the lifecycle is at least RESUMED.
// Example: navController.navigate("next_screen")
}
){
Text(text="Navigate to next screen")
}
Parameters
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current

The LifecycleOwner whose lifecycle will be observed. Defaults to the current LocalLifecycleOwner .

block: () -> Unit

The callback to be executed when the observed lifecycle state is at least State.RESUMED .

Returns
() -> Unit

A decorated function that invoke block only if the lifecycle state is at least State.RESUMED .

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026年06月24日 UTC.