app property

AppConfig? app
final

Application & lifecycle configuration.

AppConfig groups options that control how the SDK integrates with your app’s lifecycle: start/stop behavior on terminate and reboot, headless/background behavior, periodic heartbeats, scheduler windows, foreground notification, and the Android background-permission rationale dialog.

Use this class via Config.app.

BackgroundGeolocation.ready(Config(
  app: AppConfig(
    stopOnTerminate: false,
    startOnBoot: true,
  }
));

What belongs in AppConfig?

Platform notes

iOS

  • With AppConfig.stopOnTerminate set to false, the SDK creates a stationary geofence and iOS will relaunch your app in the background upon exiting that region.
  • AppConfig.preventSuspend is required for heartbeats and has a battery cost. Use sparingly.

Android

Examples

Configure once at startup:

import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg;

void main() async {
  final config = bg.Config(
    app: bg.AppConfig(
      stopOnTerminate: false,
      startOnBoot: true,
      enableHeadless: true,
      heartbeatInterval: 60,
      backgroundPermissionRationale: bg.PermissionRationale(
        title: "Allow {applicationName} to access this device's location even when the app is closed or not in use.",
        message: "This app collects location data to enable recording your trips to work and calculate distance-travelled.",
        positiveAction: 'Change to "{backgroundPermissionOptionLabel}"',
        negativeAction: 'Cancel',
      ),
      notification: bg.Notification(
        title: 'Background Geolocation',
        text: 'Tracking location',
        smallIcon: 'mipmap/ic_launcher',
      ),
      schedule: [ '1-5 09:00-17:00' ], // Weekdays 9–5
      scheduleUseAlarmManager: true,
    ),
  );

  await bg.BackgroundGeolocation.ready(config);
}

Update later at runtime:

await bg.BackgroundGeolocation.setConfig(bg.Config(
  app: bg.AppConfig(
    heartbeatInterval: 120, // slow down heartbeats
  ),
));

Migration from flat Config properties

The following legacy properties are deprecated on Config and should now be set via Config.app: Config.stopOnTerminate, Config.startOnBoot, Config.enableHeadless, Config.heartbeatInterval, Config.schedule, Config.scheduleUseAlarmManager, Config.notification, Config.backgroundPermissionRationale.

Implementation

final AppConfig? app;