Skip to content

App

classApp

Background-task and power-save utilities.

Access via BGGeo.instance.app.


Members

startBackgroundTask

fun startBackgroundTask(callback: (taskId: Int) -> Unit)

Signal to the OS that you need to perform a long-running task.

The OS keeps the app running in the background until you signal completion with stopBackgroundTask. Your callback receives a taskId which you must pass to stopBackgroundTask when finished — always call it, even if an error occurs, to avoid hanging the background task.

iOS

Uses beginBackgroundTaskWithExpirationHandler. iOS provides exactly 180 seconds of background time. The SDK automatically stops the task before the OS force-kills the app.

✅-[BackgroundTaskManager createBackgroundTask] 1
✅-[BackgroundTaskManager stopBackgroundTask:]_block_invoke 1 OF (1)
Android

Uses WorkManager. The SDK imposes a 3-minute limit before automatically force-killing the task.

 I TSLocationManager: [c.t.l.u.BackgroundTaskManager onStartJob] ⏳ startBackgroundTask: 6
 I TSLocationManager: [c.t.l.u.BackgroundTaskManager$Task stop] ⏳ stopBackgroundTask: 6
val bgGeo = BGGeo.instance

bgGeo.app.startBackgroundTask { taskId ->
    try {
        // Perform your long-running task here
        Log.d(TAG, "task executing")
        bgGeo.app.stopBackgroundTask(taskId)
    } catch (e: Exception) {
        Log.e(TAG, "Error: $e")
        bgGeo.app.stopBackgroundTask(taskId)
    }
}

stopBackgroundTask

fun stopBackgroundTask(taskId: Int)

Signal completion of a startBackgroundTask to the OS.

The OS may now suspend the app if appropriate.

val bgGeo = BGGeo.instance

bgGeo.app.startBackgroundTask { taskId ->
    // Perform your long-running task here
    Log.d(TAG, "task executing")
    // When your long-running task is complete, signal completion of taskId.
    bgGeo.app.stopBackgroundTask(taskId)
}