constBackgroundGeolocationHeadlessTask=async (event) => {const params = event.params; console.log("[BackgroundGeolocation HeadlessTask] -", event.name, params);switch (event.name) {case"terminate":// Use await for async tasksconst location =await BackgroundGeolocation.getCurrentPosition({ samples: 1, persist: false }); console.log("[BackgroundGeolocation HeadlessTask] - getCurrentPosition:", location);break; }// You must await all work you do in your task. // Headless-tasks are automatically terminated after executing the last line of your function.awaitdoWork();}BackgroundGeolocation.registerHeadlessTask(BackgroundGeolocationHeadlessTask);
This is the event-object provided to Android headless-tasks registered via BackgroundGeolocation.registerHeadlessTask.
ℹ️ See also: