Skip to content

[Feature request]: Provide an option for automatic navigation session cleanup on app termination #397

@OmniTech-admin

Description

@OmniTech-admin

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.

Metadata

Metadata

Labels

priority: p3Desirable enhancement or fix. May not be included in next release.triage meI really want to be triaged.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions