Background Applications

We’ve done most of the work to make a background application, and in some ways, News is already running in the background. Background applications could be any of these types:

Minimized application

Has a card stage (or window), but is not in the foreground view.

Dashboard application

Has a dashboard stage (or panel), but no card stage.

Background application

Has neither a card nor a dashboard stage, but wakes periodically through an alarm and can issue notifications and create dashboards or cards when appropriate.

Minimized and dashboard applications should use conventional JavaScript timers, such as setTimeout() or setInterval(), to schedule recurring actions, for instance checking for new articles. In its current form, News uses setTimeout() and runs while minimized. You’ll notice if you close the main card stage while there is a News dashboard panel, the application will run in the background, posting notifications when feeds are updated with new stories. It will not perform these updates once the device goes to sleep.

Background applications can run without a window, and can wake the device from sleep or across boots by using the Alarm service. Since the framework will close any application unless there is an open window, there isn’t another option for this type of application.

We’ll replace the setTimeout() timer with an alarm set in the setWakeup() method in app-assistant.js:

// ------------------------------------------------------------------------ ...

Get Palm webOS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.