Hello All,
The documentation here
https://wiki.appcelerator.org/display/guides/Simple+Android+Services+in+Titanium
suggests that once one starts a background service it just keeps going until stopped or the phone is powered off. I wrote a little test service to verify this. The service is very simple -
every ten seconds it increments a counter
The essential bits of my code
In the service ~~~ var bgInt = Ti.App.Properties.getInt('bgint',0); bgInt += 1; Ti.App.Properties.setInt('bgint',bgInt); ~~~
In the app
~~~ var intent = Titanium.Android.createServiceIntent({url: 'bgs.js'}); intent.putExtra('interval', 10000); var service = Titanium.Android.createService(intent); service.start(); ~~~
In tiapp.xml
~~~
In my app startup code (the app that creates and launches the service) I am checking and reporting bgint.
~~~ alert(Ti.App.Properties.getInt('bgint',0)); ~~~
So I start the app which then launches the service. I let the app run for a while and then kill it. I restart the app and it reports the bgint counter value. This time round I kill the app immediately wait a few minutes and then restart it. I expect to see that the bgint counter has incremented quite a lot. Surprise - it has incremented by just 1 or 2 - the time it took me to kill the app the second time round.
This suggests that the background service is dying as soon as I kill the app. Is this a known issue or am I doing something wrong?
Your Answer
Think you can help? Login to answer this question!