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
Contributor
Posts: 34
Registered: ‎10-27-2010
My Device: Not Specified

Question about background start page

Does the background start page run in a different thread then the foreground application?  I'm looking to using a "worker" of types to do some file IO work that is kind of involved from a performance perspective but workers don't support the API calls, so maybe the background start page is an option (assuming it does have API access)?

 

Thanks,

-Sefi

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Question about background start page

Hi Sefi,

 

There is only ever one web page running at one time.  Specifying a run on startup (background) page will have that page run when the app is installed or when the device reboots

 

If you have a different page specified when the app launches from the home screen, the old background page will be unloaded and the new page will be loaded when the user selects the icon from the home screen.

 

The old background page does not run while the new foreground page is loaded.

 

The intent of having a background page separate is if you wanted some light weight work to run in the background on start of the device as a different entry point than if the user clicks the home screen icon

 

Does that answer your question?  or make it more confusing Smiley Happy

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Contributor
Posts: 34
Registered: ‎10-27-2010
My Device: Not Specified

Re: Question about background start page

Tim,

 

That answers my question perfectly.  I have some file clean up work to do after my app downloads content, but in the main app it locks up the UI, and is not 100% required but more for maintenance to keep the storage usage low. 

 

Is there a way to start the background page when the user exit's the app or is only on startup?  is there any connection between the background and the foreground where i can preload content to speed up the UI?  

 

Last, what, if any, are the programming limitations of the background page?

 

My plan was to start playing around but your insight always saves me time so thank you!

 

-Sefi

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Question about background start page

You can subscribe to the onBackground() event to trigger your background cleanup work.  Just fire off a JavaScript function when it goes into the background and do what you need to do.  What I would suggest is that you do your cleanup work in chunks using a setTimeout() in a recursive loop.

 

The reason I say this, is that you can also trap the onForeground event to set a flag in JavaScript that your app is back in the foreground.  That way your recursive loop using the setTimeout() can check the flag to ensure that if you are back in the foreground you stop your cleanup work.

 

That way the JavaScript won't block the UI thread when your user is interacting with your app.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Highlighted
Contributor
Posts: 34
Registered: ‎10-27-2010
My Device: Not Specified

Re: Question about background start page

That makes sense, and lines up with my existing process of repackaging text files which is recursive by nature since there are several txt files to go through.  I'll give it a shot!

 

Thanks,

-Sefi

Contributor
Posts: 34
Registered: ‎10-27-2010
My Device: Not Specified

Re: Question about background start page

Tim,

 

Related question... what happens when a user cut's off a script that is writing to a text file?  Does it get corrupted or allowed to finish?  What if the battery dies in the middle of a write?  Since it's probably difficult to simulate that situation I was just curious so that  I can have code to recover from such a possibility otherwise it could leave my app crippled.

 

Thanks,

-Sefi

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Question about background start page

Those are good questions.. I would have to talk to the team to find out what would happen in those situations.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter