Super Apps Series (Java): Running in the Background Part One

For the first few posts in our Super Apps series – in the Java® stream – I wanted to talk about the BlackBerry® platform’s ability to allow applications to run in the background and on startup. This ability is important to a few of the Super App aspects, notably the “Always-on Experience,” and in making your app “Proactive and Notification-driven.” It’s also part of the “Tight Integration with the Native Apps” concept, as we’ll see later. Above all, a true Super App will be “Designed for Efficiency,” particularly when running in the background.

In this series of posts, we’ll look at several aspects of running in the background, as well as application states and how to be efficient. With this amount of material to cover, we’ll spread it over four parts. First, let’s look at how to make an application start automatically and never close, and when you’d want to do so.

The simplest example of running in the background – the literal creation of the “Always-on Experience” – is to make an application run at startup and never close. Making an application start automatically is done in the BlackBerry® Java® Plugin, by editing the BlackBerry® Application Descriptor and checking the “Auto-run on startup” checkbox.

Having made the application start automatically, the next step is to keep it running. The default behavior when the last screen is popped off the stack is to close the application. To make an application move to the background instead, override the onClose() method of the Screen to call UiApplication.getUiApplication().requestBackground().

Keeping the application running all the time is a model followed by some core apps, and this makes sense for an application that the user will frequently switch to, like messaging and IM clients. However, users will not thank you for cluttering up their switch application dialog without reason. Ask yourself this: How often will a user want a way to switch to your application quickly, that isn’t already provided through another mechanism? Also remember that you will want to stop any UI processing and release unneeded resources when you go to the background. We’ll cover this in more detail in the fourth part of this series.

Most likely, you will only want to run part of your application in the background to do certain processing or to listen for events. In this approach, your application could be separated into two parts: the UI portion that the user opens and closes as needed, and the background process which listens for specific events, such as pushed data. This is a more common model that will serve the majority of Super Apps well.

You may not need to leave the background process running all the time. Many integration options are configured during startup, such as the Homescreen icons, or ApplicationMenuItems. If your application doesn’t need to process incoming messages, your background processing can be minimized.

Check back soon as we dive into using Alternate Entry Points, and setting up a background process to listen for pushed data and other events.

Any questions so far?🙂

About Tim W.

Tim is an Open Source Technical Lead at BlackBerry, focusing on WebWorks, HTML5, and Open Source.

Good post!!Regarding: “…you will only want to run part of your application in the background to do certain processing or to listen for events. In this approach, your application could be separated into two parts: the UI portion that the user opens and closes as needed, and the background process which listens for specific events, such as pushed data…”Are you suggesting to have two different applications? Is there anyway to accomplish the above behavior in just one project (.cod, .jad)?Thanks in advance!

twindsor

You could create an Alternate Entry Point and have the user assign it to a convenience key. Not the most elegant solution, but possible. If there was reason enough and you explained it to the user then this is something that can work.

twindsor

That can be done with Alternate Entry Points, which I will cover in Part 2, which should be going up today.

Don't you think having an application continuously running (in BG or foreground) would drain the battery or use too much of battery?

http://devblog.blackberry.com/2010/07/running-in-the-background-part-three/ Super Apps Series (Java): Running in the Background Part Three | BlackBerry Developer's Blog

[…] we’ve looked at making applications start automatically and remain running in the background (part one), as well as how to use Alternate Entry Points to run a process in the background or to do setup […]

Inside BlackBerry Developers

The views expressed on any corporate or individual's personal website or any Twitter account are not necessarily those of BlackBerry. The user's Twitter account and/or personal website, any corporate website, or any comments contained on any of the foregoing have not been reviewed by BlackBerry and do not constitute an endorsement by BlackBerry.