Lifecycle
49 bites tagged Lifecycle — interview questions with model answers, and 60-second explainers.
Managing camera lifecycle in Vision Camera
Bind the isActive prop to screen focus via useIsFocused and to app state, so the camera stops when blurred or backgrounded. Camera resource lifecycle. leaving isActive always true or unmounting instead of toggling isActive.
Cancelling fetch with AbortController
Pass an AbortController signal to fetch and call abort() on unmount to avoid wasted work, race conditions, and state updates on gone components. lifecycle-aware async cleanup. ignoring cleanup and setting state after unmount.
Gesture Responder System lifecycle
A single view becomes the responder for a touch; onStartShouldSetResponder claims it at touch start, onMoveShouldSetResponder claims it on movement, then grant, move, and release callbacks fire. how RN assigns touch ownership.
Stages of an end-to-end ML pipeline
Ingest, validate, preprocess and feature engineer, train, evaluate against a baseline, then register and package for deployment, with gates between stages. the ML lifecycle as automation.
Pooled connection lifecycle and close() semantics
Borrow from pool, use, then close() returns it to the pool rather than tearing down the socket. pooled connection semantics. thinking close() physically severs the connection, or never closing and leaking connections.
Lifecycle storage tiering for compliance logs
Hot tier for 7-day query window, lifecycle rules transitioning to infrequent-access then archive, expiration at one year. object storage lifecycle design.
React to location authorization changed in Settings
Implement locationManagerDidChangeAuthorization, which fires on launch and whenever status changes, read authorizationStatus, and start updates when authorized. Observing authorization changes via the delegate.
Describe the iOS app lifecycle and SceneDelegate methods
Not running, inactive, active, background, suspended; SceneDelegate handles sceneDidBecomeActive, sceneWillResignActive, sceneDidEnterBackground, sceneWillEnterForeground. knowledge of app and scene states.
How does a ViewModel survive configuration changes and what is its scope?
The framework retains ViewModels in a store scoped to an Activity or Fragment across config changes, clearing them only when the owner finishes for good. knowledge of ViewModelStore and lifecycle scope.
What is the difference between a started service and a bound service?
Started services run until stopped via startService with no caller interface; bound services expose an IBinder and destroy when all clients unbind. Android service lifecycle and IPC boundaries.
Explain Svelte Action update and provide a reactive CSS example
Tests Svelte actions beyond initial mount. Strong answers explain update re-runs when parameters change, give a CSS custom properties example, and contrast with destroy. Red flag: suggesting the action re-runs from scratch or using reactive statements.
What is a Svelte Action? Write a simple logging action.
Define a function receiving the node, log a message, and optionally return destroy. Whether you understand a Svelte action as a lifecycle function attached to a DOM node via use: and can write its minimal signature.
Fetch data on first render and manage loading and error states
Tests lifecycle awareness and separation of concerns. Strong answer: use mount hook (onMounted, ngOnInit, onMount), hold reactive data/loading/error states, and render conditional UI branches. Red flag: calling fetch directly in template or render function.
Implement auto-cleanup reactive logic in Vue's Composition API and Svelte
Vue pairs onMounted with onUnmounted or watchEffect cleanup; Svelte uses $store auto-subscription or onDestroy. Binding streams to lifecycles without leaks.
What is ngOnInit's purpose and why prefer it over the constructor?
Tests Angular lifecycle timing and input binding. Strong answer: ngOnInit runs once after inputs are initialized, but the constructor instantiates the class before bindings exist.
How do AppDelegate and SceneDelegate responsibilities differ?
AppDelegate owns process events (launch, push); SceneDelegate owns per-window lifecycle and UI. iOS 13 scene architecture mastery. Putting all UI logic in AppDelegate or claiming SceneDelegate is optional.
UIViewController lifecycle states: network vs geometry updates
Tests UIViewController lifecycle states and separation of data vs layout. Strong answers list loadView to viewDidDisappear, start network in viewDidLoad or viewWillAppear, and geometry in viewDidLayoutSubviews. Red flag: network calls inside layout methods.
Explain the lifecycle of a State object
List initState through dispose, emphasizing didUpdateWidget reacts to parent config changes. Your grasp of StatefulWidget state transitions and framework hook timing.
Explain cold, warm, and hot app startups and three cold-start optimizations
Cold means no process; warm means process lives but activity recreates; hot means activity resumes. Three fixes: lazy-load deps, trim Application.onCreate, defer blocking I/O. App startup modes and tuning tactics.
What is the difference between viewModelScope and lifecycleScope?
This tests scope ownership across configuration changes. viewModelScope survives rotation because it lives in ViewModel, while lifecycleScope dies with UI; use former for logic and latter for UI tasks. Never launch data loads in lifecycleScope.
Explain Hilt scoping: @Singleton vs @ActivityRetainedScoped
Tests Hilt component lifecycles. Answer: @Singleton lives for the app process; @ActivityRetainedScoped survives config changes via ActivityRetainedComponent but dies when the activity finishes.
How do you share a ViewModel across multiple Fragments?
Tests ViewModel scoping and Fragment communication. A strong answer names activityViewModels or navGraphViewModels, warns about Activity memory retention and hidden coupling, and suggests a parent Fragment or data flow alternative.
What is a ViewModel and what lifecycle problem does it solve?
Tests config-change survival: ViewModel outlives Activity recreation so state survives rotation. Strong answer notes it holds non-serializable data and separates concerns, but does not survive process death.
What happens to a bound service during config changes and multiple clients?
Tests bound service reference counting. Config change destroys the Activity binding; if no other clients exist, the service stops. Multiple clients keep it alive until the last unbind. Red flag: assuming the service survives config changes without a rebind.
Get Lifecycle bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.