Skip to content

You are viewing the date archive for March2011.

How do you switch screens in a BlackBerry application?

You’re writing a BlackBerry application with several screens. How do you change from one screen to another?

If you are in the event thread (the default thread your program runs on if it’s a UI application and you haven’t started any other threads), then opening up another screen can be done by calling the pushScreen() method of the UiApplication class.

Since, in a typical case, your application derives from UiApplication, you would take a reference to your application object and call pushScreen() on it with the parameter of your new screen:

myApp.pushScreen(new MyNewScreen());

If you’re running in a worker thread, or in any context where you either don’t have access to a UiApplication or pushing a screen would not be allowed (you’re only allowed to work with UI components on the original UI thread), then pushing a screen onto the screen stack is a bit different — you need to switch to the UI thread, and then push the new screen onto the screen stack:

    new Runnable() {
        public void run() {
            Ui.getUiEngine().pushScreen(new MyNewScreen());

At Antair, we have a simple ScreenChanger class that’s part of a larger internal library that we use for all of our projects. Here’s a stripped-down version of the ScreenChanger class for you to use.

	Comments closed