Android background service
I want to use background service in my titanium application.
I've used every code that needs to be pasted into the Titanium Android app.
In the TiApp.xml file: register the service here
Here BGServ.js file is located in my app / lib folder .
In BGServ.js file: our service file code
var service = Titanium.Android.currentService;
var intent = service.intent;
Ti.API.info('Background Service Started');
Ti.API.info('Background Service of Platform : ' + Titanium.Platform.osname + ' Started');
service.addEventListener('resume', function(e) {
Titanium.API.info('Service code resumes, iteration ' + e.iteration);
});
service.addEventListener('pause', function(e) {
Titanium.API.info('Service code pauses, iteration ' + e.iteration);
});
In the index.js file: Here we create the Service Intent
var intent = Titanium.Android.createServiceIntent({
url : '/BGServ.js'
});
intent.putExtra('interval', 1000);
intent.putExtra('message_to_echo', 'Test Service');
Titanium.Android.startService(intent);
Problem . Android service is not running in my project. BGServ.js has Ti.API.info () which also don't print to the console. This is where I help me.
TiSDK Version: 3.5.0 GA
Thank,
Abidhusain
source to share
Found android background service solution in titanium applicator
In the TiApp.xml file:
Note that here, in the url attribute, you do not need to add "\" before the filename.
And also place the background service file only in the assets folder in your application.
In the bg_service.js file : our service file code
var service = Titanium.Android.currentService;
var intent = service.intent;
Ti.API.info('Background Service Started');
Ti.API.info('Background Service of Platform : ' + Titanium.Platform.osname + ' Started');
service.addEventListener('resume', function(e) {
Titanium.API.info('Service code resumes, iteration ' + e.iteration);
});
service.addEventListener('pause', function(e) {
Titanium.API.info('Service code pauses, iteration ' + e.iteration);
});
In the Index.xml file: here we create the intent and start the background service
var intent = Titanium.Android.createServiceIntent({
url : 'bg_service.js'
});
intent.putExtra('interval', BG_INTERVAL_SECONDS);
Titanium.Android.startService(intent);
Note that here, in the url attribute, you do not need to add "\" before the filename.
Issue Resolved by above code and also take care of **"\"** in url attribute
If anyone finds another solution, replay here.
Thank,
Abidhusain
source to share