Android Headless Task
Experimental
A special task that gets executed when the app is terminated, but the plugin was configured to continue running in the background (option stopOnTerminate: false
). In this scenario the Activity was killed by the system and all registered event listeners will not be triggered until the app is relaunched.
Note: Prefer configuration options url
and syncUrl
over headless task. Use it sparingly!
Task event
Parameter | Type | Description |
---|---|---|
event.name | String | Name of the event [ “location”, “stationary”, “activity” ] |
event.params | Object | Event parameters. See Events |
Keep in mind that the callback function lives in an isolated scope. Variables from a higher scope cannot be referenced!
Following example requires CORS enabled backend server.
BackgroundGeolocation.headlessTask(function(event) {
if (event.name === 'location' ||
event.name === 'stationary') {
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://192.168.81.14:3000/headless');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify(event.params));
}
return 'Processing event: ' + event.name; // will be logged
});