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
Regular Contributor
Posts: 63
Registered: ‎06-08-2012
My Device: BlackBerry
My Carrier: BlackBerry

How to run background a process on WebWorks

Hi everyone,

 

I want to run background a process on my WebWorks App.

It is imposible?

 

If it is able, you will show me example?

 

See you response soon!

Thanks a lot!

An Pham,

Developer
Posts: 410
Registered: ‎06-03-2010
My Device: Z10 Red
My Carrier: Free

Re: How to run background a process on WebWorks

You can use HTML 5 's Web Worker:

 

http://www.html5rocks.com/en/tutorials/workers/basics/

 

 

Developer
Posts: 314
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha
My Carrier: TMN

Re: How to run background a process on WebWorks

I'm not sure what the OP means with the question.

Do you want to run an asynchronous functions (use Web Worker like suggested) or to have a background process running when your app is not open?

Nuno
Regular Contributor
Posts: 63
Registered: ‎06-08-2012
My Device: BlackBerry
My Carrier: BlackBerry

Re: How to run background a process on WebWorks

Hi nunodonato,
When my app is open, I want to have a background process running , and when I link to other page html of webwork app, this background process running is continue.

See your response soon!
An Pham
Regular Contributor
Posts: 63
Registered: ‎06-08-2012
My Device: BlackBerry
My Carrier: BlackBerry

Re: How to run background a process on WebWorks

Hi everyone,

 

function backgroundThread() {

            var okay = false;

            var i = 0, limit = 10000, busy = false;

           

            var count = 0;

            var processor = setInterval(function () {

                  count++;

                alert("Auto submit server! "+count);

                if (!busy) {

                    busy = true;

 

                    if (condition) {

                        okay = true;

                    }

 

                    if (++i == limit) {

                        clearInterval(processor);

                    }

 

                    busy = false;

                }

 

            }, 10000);

}

     

backgroundThread();

 

I have a JavaScript code which run background well.

 

I have just test on Ripple simulator (on Chrome), link to other page and it is work well.

 

Unfortunately, it is not work in PlayBook. It just work only page which have this JavaScript code (It is not work when I link to other page).

 

Do you have any opinions?

 

Best Regards,

Developer
Posts: 314
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha
My Carrier: TMN

Re: How to run background a process on WebWorks

Hi!

I'm not sure about this, but I guess that if you are changing pages then the expected behavior would be to stop any running timeouts. In my view, the playbook does it correctly Smiley Happy

For what you want to do, Web Workers is the correct approach.

 

PS - you should avoid changing pages in a webworks app

Nuno
Developer
Posts: 410
Registered: ‎06-03-2010
My Device: Z10 Red
My Carrier: Free

Re: How to run background a process on WebWorks

Does HTML5 allows an access to the same Webworker for two windows with different location?

 

But I agree, you should try to avoid changing page.

Developer
Posts: 161
Registered: ‎02-08-2012
My Device: PlayBook
My Carrier: None yet

Re: How to run background a process on WebWorks

er.. do webworkers continue operating even when the screen is off?  Considering that all other javascript execution seems to halt. 

 

 

Regular Contributor
Posts: 63
Registered: ‎06-08-2012
My Device: BlackBerry
My Carrier: BlackBerry

Re: How to run background a process on WebWorks

No.
I want to start my app, a process is run background to do something.

And when I close my app, the process is closed too
Regular Contributor
Posts: 81
Registered: ‎03-09-2012
My Device: PlayBook & Bold 9780
My Carrier: n/a

Re: How to run background a process on WebWorks

[ Edited ]

The answer is posted by nunodonato, still dangling at the bottom of the forum posts list.

 

The essential part is in the config.xml:

 

<content src="index.html">
<rim:background src="background.html" runOnStartup="true" />
</content>

 but in your case you want runOnStartup="false" (only start if the app starts, not if the device boots)