Skip to content

Instantly share code, notes, and snippets.

@ricardoalcocer
Last active September 3, 2021 14:43
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ricardoalcocer/5200359 to your computer and use it in GitHub Desktop.
Save ricardoalcocer/5200359 to your computer and use it in GitHub Desktop.
Appcelerator Titanium Android Background Service
// start service
var SECONDS = 20; // every 10 seconds
var intent = Titanium.Android.createServiceIntent({
url: 'logservice.js'
});
intent.putExtra('interval', SECONDS * 1000); // Needs to be milliseconds
Titanium.Android.startService(intent);
// stop service
var intent = Titanium.Android.createServiceIntent({
url: 'logservice.js'
});
Titanium.Android.stopService(intent);
// for Alloy this file goes in /assets
Ti.API.info('write something');
<android xmlns:android="http://schemas.android.com/apk/res/android">
<services>
<service url="logservice.js" type="interval"/>
</services>
</android>
@julien9999
Copy link

So what does this do exactly ?
Can I use this to write a function inside logservice.js and have it run every X minutes ?
Will it work and the function be executed when the app is fully closed and device restarted ?
thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment