BlackBerry applications behave very much like ordinary desktop applications. If you’ve had experience with C, C++, or Java on the desktop, some of the ideas in the previous probably seemed very familiar to you. Specifically, the main method for a BlackBerry application is identical to the main method for a Java SE application (which is very similar to C’s). While there are exceptions for specific needs, almost all BlackBerry applications will follow the same life cycle. In this book, all of our applications will fundamentally look like the Hello World application we created in the last chapter.
Starting the Application
An application is generally started in one of three ways:
In all cases, the main method is the first entry point for your application. The BlackBerry device will create a process, which will call that method. Whenever the main method exits, the process is terminated and your application exits. This means that if you want your application to do anything, you’d better do it in that main method.The main method takes an array of java.lang.String objects as parameters. For the most part, this array is empty, but parameters can be passed in if you define them in the project properties or if they’re passed by another process that is starting your application.
Creating the Application
All BlackBerry applications that want to present a user interface to the user must extend UiApplication. You can only create one instance of UiApplication for any application process; the BlackBerry runtime will throw an exception if you try to instantiate a second one. Even applications with no user interface must extend net.rim.device.api.system.Application, but those types of applications are outside the scope of this. You can always access your application instance using the static method UiApplication.getUiApplication(). This actually returns an instance of your application class, so from anywhere in Hello World, the following is allowed:HelloWorldApp helloWorld = (HelloWorldApp)UiApplication.getUiApplication();
Invoking the Event Thread
The event thread is started for you by the BlackBerry operating system, but it doesn’t start processing events and drawing the UI until you explicitly tell it to. You do this with the UiApplication.enterEventDispatcher() call that you saw in the last chapter. Once this method is called, the thread that entered into the main method passes from your direct control and takes up the task of listening for user interface input and drawing the user interface to the screen. You’ll still get a chance to do work on the thread, but for the most part, its activities are scheduled by the BlackBerry operating system. enter Event Dispatcher won’t return for the entire life cycle of your application, so if there’s anything your main thread must do before calling this (for example, some types of initialization) you have only one chance.
The application responds to keyboard input, trackball, or touch screen movements and clicks and to other events like system messages.
Exiting the Application
Generally, a BlackBerry application exits when the last screen is removed from the display stack (by closing it). You may have noticed the System.exit() method, which will exit the application, but it’s recommended to avoid this and properly clean up the application on exiting by closing all screens instead. When the application exits, all application state will be cleaned up, and the next time the user clicks the application icon the main method will be called again with a new process.
BLACKBERRY Related Interview Questions
|J2ME Interview Questions||BLACKBERRY Interview Questions|
|Android Interview Questions||Retail Interview Questions|
|Telecommunication Project Management Interview Questions||Mobile Testing Interview Questions|
|Telemarketing Interview Questions||Mobile Application Testing Interview Questions|
|Mobile Marketing Interview Questions||Telecom Billing Interview Questions|
|Mobile Application Architect Interview Questions|
Setting The Stage
What Makes A Blackberry Application?
User Interface Basics
Beyond The Basics Of User Interfaces
Hello Out There! Making A Network-enabled Application
Where Am I? Using Location-based Services
Getting Your App Out There: Packaging And Publishing
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.