IBM Worklight - 如何在后台进程中使用Worklight [英] IBM Worklight - How to use Worklight in a background process

查看:155
本文介绍了IBM Worklight - 如何在后台进程中使用Worklight的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序即使在用户按下后退按钮后仍应连续运行。
它必须每半小时使用POST方法将一些数据发送到远程服务器中的数据库。即使在用户按下后退按钮并且应用程序应该仅在移动设备关闭时停止,也会发生这种情况。

I have an application that should run continuously even after the user presses the back button. It has to send some data using POST method to my database in a remote server for every half an hour. This should happen even after the user has pressed the back button and the app should only stop when the mobile is switched off.

我已设置HTTP适配器以发送POST数据以及一个HTML文件,用于在启动时调用适配器程序,我不知道如何使其成为后台或运行哪些代码以保持每半小时发送一次POST数据。

While I have set up the HTTP Adapter to send POST data and also an HTML file to call the adapter procedures on launch, I dont know how to make it background or which code to run to keep sending the POST data every half an hour.

推荐答案

这听起来像是在Android上运行。

It sounds like you are running on Android.


  1. Android中的预期行为是按下后退按钮退出应用程序。

  2. 按主页按钮进入后台。

因此,我不认为你在按下后退按钮时应该这样做...或者你应该至少让用户选择退出或移动到后台(你可以覆盖后退)按钮使用 WL.App.overrideBackButton )。

So, I don't think you should do this when pressing the Back button... or maybe you should at least present the user the choice of either quitting or moving to the background (you can override the Back button by using WL.App.overrideBackButton).

那就是说,我不熟悉一个程序化的方法来移动到后台而不是退出(可能有一个现有的Cordova插件或其他方式来执行此操作)。

That said, I am not familiar with a programmatic method to move to the background instead of quitting (maybe there is an existing Cordova plug-in or another way that does this).

实现此目的的另一种方法是使用Android后台服务,但是,Worklight在其Native API中没有支持这样做。

The other way to accomplish this is by using an Android Background Service, however, Worklight does not have support in its Native API to do this.

至于Worklight会发生什么应用程序在后台,我从未尝试过,所以我无法确定,但尝试使用 WL.Client.setHeartBeatInterval 保持与Worklight Server的连接,并编写一些逻辑发送适配器请求。看看这对你有用......

As for what happens when the Worklight application is in the background, I have never tried it myself, so I cannot be certain at all, but try using WL.Client.setHeartBeatInterval to keep alive the connection to the Worklight Server and write some logic that sends the adapter requests. See if that would work for you...

我发现这个:
​​如何在phonegap中创建插件以在后台运行应用程序?

也许你可以将它按到你的Worklight项目中(如果上面的心跳方法不起作用)。

I have found this: How to create plugin in phonegap to run the application in background?
Maybe you'll be able to massage it into your Worklight project (in case the heartbeat approach above does not work).

有关在后台运行的更多信息:

Android:

More information on running in the background:
Android:

  • http://developer.android.com/training/basics/activity-lifecycle/index.html
  • http://developer.android.com/reference/android/app/Activity.html

iOS:

  • http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html

这篇关于IBM Worklight - 如何在后台进程中使用Worklight的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆