Shashank Jain
Shashank Jain

Reputation: 857

How to run a background process using Worklight?

Can you please guide me how to run a background process/service while using Worklight in Android? I have looked at many places but found nothing helpful regarding this.

Upvotes: 2

Views: 889

Answers (3)

uriz
uriz

Reputation: 107

Technically speaking, it sounds like the flow you describe requires running a plugin from the javascript code, and starting a service from within the plugin. The async issues here could be a bit tricky - as the return "from" the plugin to the js is async, but also the thread itself (service) inside the native code. So wouldn't it be enough to run your native code synchronously ? (this would be synchronous "relative" to the native but async "relative" to the js)

android service - http://developer.android.com/guide/components/services.html

Upvotes: 1

Nick Roth
Nick Roth

Reputation: 3077

I'll assume you're asking about running a background process when the app is in the background. The problem is that JavaScript in PhoneGap does not run when the app is in the background. To provide background process capability you'll need to create a plugin to manage the background process.

http://docs.phonegap.com/en/2.2.0/guide_plugin-development_index.md.html

There used to be some documentation from Worklight about creating PhoneGap plugins to be used in Worklight apps but I can't seem to find it.

There is already an existing plugin to help manage background processes in Android

https://github.com/phonegap/phonegap-plugins/tree/master/Android/BackgroundService

Upvotes: 2

Anton
Anton

Reputation: 3166

If you're talking about JavaScript part of the application you can detach a thread using setTimeout(function(){...}, 0);. Thats the closest thing to background thread JavaScript have to provide. You can, of course, look into web workers, but that will make things a bit more complex.

Upvotes: 0

Related Questions