我想在我的钛应用程序中使用后台服务。
我使用了所有需要插入到钛Android应用程序中的代码。
在TiApp.xml文件中:这里的注册服务
<services>
<service url='BGServ.js' type="interval"/>
</services>
这里"BGServ.js“文件放在我的app/lib文件夹中。
在BGServ.js文件中:我们的服务文件代码
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);
});
在index.js文件中:我们在这里创建服务意图
var intent = Titanium.Android.createServiceIntent({
url : '/BGServ.js'
});
intent.putExtra('interval', 1000);
intent.putExtra('message_to_echo', 'Test Service');
Titanium.Android.startService(intent);
问题:Android没有在我的项目中工作。在BGServ.js中,有一个也没有在控制台中打印的Ti.API.info()。我在这里,帮帮我。
TiSDK版本:3.5.0GA
谢谢,
亚比乌珊
发布于 2015-06-17 09:45:11
在钛Appcelerator中找到了安卓后台服务的解决方案
在TiApp.xml文件中:
<services>
<service type="interval" url="bg_service.js"/>
</services>
注意到在url属性中不需要在文件名之前添加"\"。
并将后台服务文件仅放在应用程序上的"assets“文件夹中。
在"bg_service.js“文件中:我们的服务文件代码
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);
});
在Index.xml文件中:我们在这里创建意图并启动后台服务
var intent = Titanium.Android.createServiceIntent({
url : 'bg_service.js'
});
intent.putExtra('interval', BG_INTERVAL_SECONDS);
Titanium.Android.startService(intent);
注意到在url属性中不需要在文件名之前添加"\"。
Issue Resolved by above code and also take care of **"\"** in url attribute如果有人找到其他解决方案,那就在这里重放一遍。
谢谢,
亚比乌珊
https://stackoverflow.com/questions/30593098
复制相似问题