Tutorial :Where to put GUI based start-up code in a Blackberry App?


I'd like to know the proper place to put GUI based sequential start-up code in my Blackberry app.

In main(), I create MyApp and enterEventDispatcher()  I have UiApplication (MyApp)  In the MyApp CTOR:  - I create a MainScreen (MyMain)  - I call pushScreen() on MyMain  

When the event dispatcher starts, is there an event I can listen for in my MainScreen that will give me the event thread where I can happily do synchronous start-up tasks?

I can use invokeLater() but I want each call to block because their order is important in this phase. invokeAndWait() throws an exception in most cases where I've attempted to use it.

I've attempted the code below but I get an exception when trying to run on the "Testing 1 2 3" line.

      public class MyApp extends UiApplication {            static public void main(String[] args) {              new MyApp().enterEventDispatcher();          }            public MyApp()          {              MyView theView = new MyView();              theView.startUpdateTimer();              pushScreen(theView);                Dialog.alert("Testing 1 2 3");          }      }  


If it's pretty quick UI stuff (creating a screen, pushing it onto the stack), do it from the main thread before calling enterEventDispatcher. You can actually do as much as you want, just the user experience will be worse if your app takes a long time.

The thread that calls enterEventDispatcher basically becomes the event dispatch thread, so you're safe to do any GUI stuff on that thread before calling enterEventDispatcher.

Specifically, don't call invokeAndWait from the main thread - that'll cause deadlock and probably an exception.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »