I already implement background service for my app. I am using it for getting user current location by using location services.
I will explain the way i implement this - "XYZ.js" - Screen where user distance display. Following code is added to set register background service -
var iService = Ti.App.iOS.registerBackgroundService({
url : 'BackgroundService.js'
});
once app go to background, background service start and collect user locations. When app come is at foreground i fired following event -
Ti.App.fireEvent('stopBackgroundService');
In "BackgroundService.js" - there is listener as -
Ti.App.addEventListener('stopBackgroundService',function(){
Ti.App.currentService.stop();
});
But after finishing this all location base work, when i move to other screen and taking app to background, location services start again. Due to Which device battery drains.
Any suggestions? Thanks in advance.
After playing with it, I solved it by following way - 1. Create global variable as
`Ti.App.BackgroundService`
when location services based work finish, stop and unregister background service as
Ti.App.BackgroundService.stop();
It works as expected.
Thanks