didChangeAppLifecycleState method
Called when the system puts the app in the background or returns the app to the foreground.
An example of implementing this method is provided in the class-level documentation for the WidgetsBindingObserver class.
This method exposes notifications from SystemChannels.lifecycle.
See also:
- AppLifecycleListener, an alternative API for responding to application lifecycle changes.
Implementation
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
// On resume, let the shared session rotate if it has gone idle past the
// timeout — so both analytics grouping and session-scoped frequency caps
// see a fresh session. Owned here (the SDK's lifecycle observer), not in
// analytics.
if (state == AppLifecycleState.resumed) {
SessionManager.instance.maybeExpire();
}
// detached = permanent process destruction. Not paused (every background).
DigiaAnalyticsService.instance.appLifecycleChanged(state);
if (state == AppLifecycleState.detached) {
_activePlugin?.teardown();
_activePlugin = null;
}
// Closes/reopens the live-test stream on background/resume so a stale
// presence lease isn't held between heartbeats.
LiveTestService.instance.onAppLifecycleChanged(state);
}