Core code for the Cordova Background Service