I built an app that tracks the location of the user even if the app is closed. But I want it to be destroyed, when the user kills the app via application exit in Android. Currently I still get the notification that the app is used in the background even if I closed it via task manager of my real device.
This is the message popping up after killing the app in the taskmanager, which tells that the app is still running in the background.
I am using WillStartForegroundTask from the geofence_service package.
Here is my code:
class CityDetailsScreen extends StatefulWidget {
CityDetailsScreen();
@override
_CityDetailsScreenState createState() => _CityDetailsScreenState();
}
class _CityDetailsScreenState extends State<CityDetailsScreen> {
bool permissionGranted = false;
final geofenceService = GeofenceService.instance.setup(
interval: 5000,
accuracy: 100,
loiteringDelayMs: 60000,
statusChangeDelayMs: 10000,
useActivityRecognition: false,
allowMockLocations: true,
geofenceRadiusSortType: GeofenceRadiusSortType.DESC);
@override
Widget build(BuildContext context) {
return WillStartForegroundTask(
onWillStart: () {
// You can add a foreground task start condition.
return geofenceService.isRunningService;
},
androidNotificationOptions: AndroidNotificationOptions(
channelId: 'geofence_service_notification_channel',
channelName: 'Geofence Service Notification',
channelDescription:
'This notification appears when the geofence service is running in the
background.',
channelImportance: NotificationChannelImportance.HIGH,
priority: NotificationPriority.HIGH),
iosNotificationOptions: IOSNotificationOptions(),
notificationTitle: 'Aschaffenburger Geheimnisse läuft im Hintergrund',
notificationText: 'Klicke, um in die App zurückzukehren!',
child: AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light,
child: Scaffold(
body: Container()
)
)
);
}
@override
void dispose() {
print("DISPOSE GeofenceService");
GeofenceService.instance.stop();
super.dispose();
}
}
The service should be completely destroyed when I detach the app!
Any ideas?
