HeadlessEvent Android only¶
Event delivered to a headless task registered via BackgroundGeolocation.registerHeadlessTask (React Native and Flutter). Cordova and Capacitor never deliver it to JavaScript: their headless events go to a native Android class instead — see AppConfig.enableHeadless.
Headless tasks allow the app to handle SDK events while running in the
background without a UI — including after the app has been terminated by the
user. Each task invocation receives a HeadlessEvent describing which SDK
event occurred and carrying the associated payload.
const headlessTask = async (event: HeadlessEvent) => {
const { name, params } = event;
console.log("[HeadlessTask]", name, params);
if (name === "location") {
const location = params as Location;
console.log("[HeadlessTask] location:", location);
} else if (name === "http") {
const httpEvent = params as HttpEvent;
console.log("[HeadlessTask] http status:", httpEvent.status);
}
};
BackgroundGeolocation.registerHeadlessTask(headlessTask);
Members¶
name¶
name:Event| 'locationerror';
The SDK event that triggered this headless task invocation (e.g.
location, http, geofence, heartbeat, terminate).
Also locationerror, which has no listener of its own: in the foreground a
location error reaches the failure callback of onLocation. On React Native
its params is the LocationError code. For notificationaction,
params is the buttonId of the tapped action.
params¶
Event payload corresponding to name. Cast this to the appropriate event
type based on the value of name (e.g. Location for location,
HttpEvent for http).