What are the android lifecycle events ?
The Activity lifecycle defines how Android creates, displays, pauses, and destroys a screen. Correct usage ensures good performance, no leaks, and a smooth user experience.
onCreate(): Called once when activity is created. best for ,- Dependency Injection
- Initializing ViewModels
onStart(): The Activity becomes visible but not yet interactive.- Good place for creating observers
onResume(): The Activity is in the foreground and fully interactive.- Start Sensors, Camera or Location Updates.
- Perform data Synchronization
- Resume animations or realtime updates
onPause(): Called when activity is about to lose focus.- Used to pause or suspend ongoing work.
- Best place to pause Camera, Sensors, Listeners.
onStop(): When activity is no longer visible.- Used to release resources like Media Playback.
onDestroy(): Final Cleanup when activity is destroyed.
Comments
Post a Comment