English topic guide inspired by the original iOS Developer Notebook, expanded for both iOS and Android teams.
@main
struct MyApp: App {
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup { RootView() }
.onChange(of: scenePhase) { phase in
if phase == .background { Task { await AppState.shared.persist() } }
}
}
}
class App : Application(), DefaultLifecycleObserver {
override fun onCreate() {
super.onCreate()
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
}
override fun onStop(owner: LifecycleOwner) { AppState.persist() }
}