teogor / ceres

🪐 Ceres is a comprehensive Android development framework designed to streamline your app development process. Powered by the latest technologies like Jetpack Compose, Hilt, Coroutines, and Flow, Ceres empowers developers to build modern and efficient Android applications.
https://source.teogor.dev/ceres
Apache License 2.0
65 stars 4 forks source link

Add Lifecycle Observation Utilities for Activity, Application, and Composable Components #146

Closed teogor closed 1 year ago

teogor commented 1 year ago

This PR introduces a set of utility functions to observe the lifecycles of Activity, Application, and Composable components in a Jetpack Compose application. These utilities enable developers to execute custom actions when these components enter or exit the foreground.

The following functions have been added:

  1. ObserveActivityLifecycle: Observes the lifecycle of the current Activity, allowing actions to be performed when it enters or exits the foreground.

  2. ObserveApplicationLifecycle: Observes the lifecycle of the Application, enabling actions to be taken when it enters or exits the foreground.

  3. ObserveComposableLifecycle: Observes the lifecycle of the current Composable, allowing actions to be performed when it enters or exits the foreground.

Additionally, a generic OnLifecycleEvent composable function has been introduced for observing the lifecycle of any LifecycleOwner and executing custom actions upon lifecycle events.

These utilities provide a convenient way to manage lifecycle-related behavior in Jetpack Compose applications.