Keeping a Close Eye on BlackBerry App Callbacks - dummies

Keeping a Close Eye on BlackBerry App Callbacks

By Karl G. Kowalski

Part of BlackBerry Application Development For Dummies Cheat Sheet

Your BlackBerry application uses callbacks to allow the smartphone’s OS to call into your application for specific operations. Your BlackBerry application itself likely employs callbacks to allow the threads it creates to inform the main process of your application that the thread has completed its job.

Here are a few things to keep in mind when dealing with callbacks:

  • Implement your BlackBerry application’s callbacks as an interface, not a class. This allows you the flexibility to make any concrete class already in your application an object that can receive the message from the thread.

  • Provide both success and failure methods in your callback implementation. You should program as if something bad will happen so you’ll be prepared when it does, such as a failure to reach a network service or a BlackBerry running low on memory unable to download a large file.

  • If your callback is going to modify what’s on display or interact with the user, place the code to be executed within a Runnable object and pass that object into a call to UiApplication.invokeLater( Runnable r ).