Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
Posts: 172
Registered: ‎05-01-2010
My Device: Z10
My Carrier: O2

recurring tasks

Hi,

 

do you have any recommendation for a recurring task that needs to be done in the background? I am asking because I need to drop some entries in a database from time to time in a webworks project.

What I am thinking about was, first at the start for sure or (if this app is capable of) when a push message arrives.

 

How would you solve this in a clean way?

 

 



----------------------------------------------------------
find my widgets -> http://blackberry.itbert.de
Developer
Posts: 268
Registered: ‎08-19-2009
My Device: Bold 9700

Re: recurring tasks

1. You can keep your app running in the background by catching the exit event using the blackberry.app.event.onExit() and requesting blackberry.app.requestBackground()

 

2. Use Javascript's setInterval(fn, interval) to perform your function fn at every given interval (measured in milliseconds). To also call it at app initialization, define an init() function with your actions and set your content HTML's <body onload="init()">.

 

3. You can (and must) capture push messages via the OpenB*SPushListener onPush() callback method. You can do whatever you want in there. See here for an example.

Developer
Posts: 172
Registered: ‎05-01-2010
My Device: Z10
My Carrier: O2

Re: recurring tasks

Does setInterval not drain the battery? 



----------------------------------------------------------
find my widgets -> http://blackberry.itbert.de
Developer
Posts: 268
Registered: ‎08-19-2009
My Device: Bold 9700

Re: recurring tasks

[ Edited ]

I'm not sure about that, I couldn't find any documentation on it. However, I assume any other manual implementation would drain the battery as much or more than the native setInterval(). Currently there is no native WebWorks API that duplicates this functionality.

 

I use setInterval in my app without much issue. I'm running openBISPushListener() once an hour. Somebody else may have further insight into the CPU (read: battery) usage of the setInterval though.

 

To maximize the performance of setInterval():

 

  1. Pass it a function rather than a string
  2. Have as few intervals set as possible
  3. Make the interval durations as long as possible
  4. Have the code running each time as short and simple as possible