-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Is there an existing issue for this?
- I have searched the existing issues
Use case
When using google_navigation_flutter, the navigation session persists after the app is force-closed. This is a challenge because, as an application developer, it's impossible to distinguish between two common user scenarios from within the Flutter framework:
Temporarily backgrounding the app: The user switches to another app or locks the screen. In this case, I want the navigation to continue running in the background. This is a critical feature for a seamless navigation experience.
Explicitly closing the app: The user swipes the app away from the recent apps screen to terminate it. In this scenario, the navigation session should be completely terminated to prevent unwanted battery and data consumption.
Currently, both of these actions trigger the AppLifecycleState.paused state in Flutter. There is no reliable, cross-platform way to detect that the app is being forcefully terminated versus simply being paused.
This leaves developers with a difficult choice: either let the navigation run indefinitely after the app is closed, or disable background navigation altogether.
Proposal
The ideal solution would be a new option provided by the SDK to handle this distinction automatically at the native level, where this information is available. The SDK could monitor the lifecycle of its host process and act accordingly.
I propose a new option during initialization:
Dart
// Suggested API change
await GoogleMapsNavigator.initializeNavigationSession(
// This new flag would be false by default to maintain current behavior.
cleanupOnAppTermination: true
);
How it would work:
When cleanupOnAppTermination is set to true, the SDK's native component (e.g., the Foreground Service on Android) would be responsible for monitoring the host application process. If the process is destroyed (for example, by the user swiping it away or by the OS), the native service would then automatically stop the guidance and clean itself up.
This would allow the navigation to persist correctly when the app is in the paused state (backgrounded) but ensure a full cleanup when the app is truly terminated.