html5
1 / 19

BlackBerry App Lifecycle Java ME API

BlackBerry App Lifecycle Java ME API. BlackBerry App Life Cycle. Application Starts Three ways to start an app: User clicks app icon App starts automatically on startup or reboot App is started by another app Starting point in your application class is main() method.

eden-best
Download Presentation

BlackBerry App Lifecycle Java ME API

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. BlackBerry App Lifecycle Java ME API

  2. BlackBerry App Life Cycle • Application Starts • Three ways to start an app: • User clicks app icon • App starts automatically on startup or reboot • App is started by another app • Starting point in your application class is main() method Wendi Jollymore, ACES

  3. BlackBerry App Life Cycle • Application Object Is Created • Triggered in the main() method • You instantiate your application class that extends UiApplication • Application classes with a Ui must extend UiApplication class • Can only have one UiApplication instance for any application • Otherwise RuntimeException is thrown. Wendi Jollymore, ACES

  4. BlackBerry App Life Cycle • Event thread is started • main() is the main thread or process that’s running • Do anything you need to do here before you pass control to BB O/S • enterEventDispatcher() method call • Takes control of the main thread • Draws the main screen and listens for events • Won’t return, so if you need something else done in main(), do it first Wendi Jollymore, ACES

  5. BlackBerry App Life Cycle • Events are processed • User events triggered by input from trackball, touch screen, keyboard, etc • Other events • Application Exits • When the last screen is removed from the stack. • Avoid System.exit() !! • Close all screens until the last screen is closed. • Proper clean up of all application state Wendi Jollymore, ACES

  6. What is the API? • Application Program Interface • The collection and definition of building blocks available in a language • Descriptions of classes and their public methods • http://en.wikipedia.org/wiki/Api • Where to read the API docs? • http://www.blackberry.com/developers/docs/6.0.0api/index.html • Go to any JDE folder and select BlackBerry JDE API Reference Wendi Jollymore, ACES

  7. Java ME API • Java ME – Micro Edition • For developing mobile apps • Runs on custom JVM for BlackBerry • BlackBerry Java Virtual Machine • MIDP 2.0 Standard– Mobile Information Device Profile • http://www.webopedia.com/TERM/M/MIDP.html • Part of Java ME API used for various mobile devices (not just for RIM) • Contains APIs for persistent storage, user interface, networking Wendi Jollymore, ACES

  8. Java ME API • CLDC – Connected Limited Device Configuration • http://www.webopedia.com/TERM/C/CLDC.html • A specification for a stripped down virtual machine • For devices with very limited memory • Contains minimalist versions of java.lang, java.util, java.io • Contains java.microedition.io for network connections Wendi Jollymore, ACES

  9. Java ME API • Other API Extensions specific to BlackBerry devices • User Interface • Persistent Data Storage • Networking • Event Listeners • Application Integration • Additional utilities for encryption, compression, location-based services, etc. Wendi Jollymore, ACES

  10. Using API to Create App • Simplest: Start with two classes • An application class • The main application where it all starts • Extends UiApplication class • Three main tasks to perform: • Create an instance of the app • Create main screen and push onto display stack • Start the event dispatch thread Wendi Jollymore, ACES

  11. Using API to Create App • Simplest: Start with two classes (continued) • A screen class • A visible display • Extends MainScreen class • Could have components, images, user input, etc • Components = Fields • net.rim.device.api.ui.Field • Layout = Managers • net.rim.device.api.ui.Manager Wendi Jollymore, ACES

  12. UiApplication Class • net.rim.device.api.ui.UiApplication • Child of Application class • A non-gui program would extend this • Base class for all UI applications • Contains a screen stack • Only top screen is ever visible • pushScreen(screen) adds a screen to the stack • Lays out and prints the screen object • A screen can only be pushed onto the stack once, or exception occurs Wendi Jollymore, ACES

  13. UiApplication Class public class MyApp extends UiApplication { public MyApp() { MyScreen scr = new MyScreen(); pushScreen(scr); } // ... } Wendi Jollymore, ACES

  14. UiApplication Class • Event dispatcher thread • enterEventDispatcher() called on your application class • Takes control of main thread • Handles all drawing and event-handling • Never returns; ends when application ends • Call this in the application’s main() method Wendi Jollymore, ACES

  15. UiApplication Class public class MyApp extends UiApplication { public MyApp() { MyScreen scr = new MyScreen(); pushScreen(scr); } public static void main(String[] args) { MyApp app = new MyApp(); app.enterEventDispatcher(); } } Wendi Jollymore, ACES

  16. MainScreen Class • net.rim.device.api.ui.container. MainScreen • Child of Screen/FullScreen class • Has a VerticalFieldManager, title area, default menu, etc • In the MainScreen constructor is where you’d create and lay out your main UI Wendi Jollymore, ACES

  17. MainScreen Class public class MyScreen extends MainScreen { public MyScreen() { LabelField label = new LabelField(“Hello!"); add(label); LabelField title = new LabelField("Java ME"); this.setTitle(title); } } Wendi Jollymore, ACES

  18. Hierarchy • It’s interesting to note the inheritance hierarchy of these classes: Wendi Jollymore, ACES

  19. Exercises and Homework • Exercise: • Do the exercise in the Lesson 2 notes • For next class: • Read Chapter 4 of Beginning BlackBerry Wendi Jollymore, ACES

More Related