Using invokeLater( ) in UiApplication

1.5k Views Asked by At

Can i include my try catch block with invokeLater statement in UiApplication for blackberry.

What is the exact purpose of using an invokeLater mothod.And how is it to be invoked?

Here is the code

     UiApplication.getUiApplication().invokeLater(new Runnable() 
    {
        public void run() 
       {
             try{
                  //Statements
                 }
             catch()
             {
             }
        }
    });
1

There are 1 best solutions below

2
On

Yes, you can include your own try-catch -blocks inside the run-method. The purpose of the invokeLater and invokeAndWait is to make it possible to do things affecting UI from outside the event-thread: The event thread is the thread that has the event lock, meaning that the thread is responsible for executing all code for drawing and handling events. Only the event thread can process incoming events and update the UI of the associated application.

When you call one of the invokeLater-methods or invokeAndWait, your Runnable is queued to be run inside the event-thread. With invokeLater, your code calling the method can continue running, and the Runnable will be run in the event-thread sooner or later. With invokeAndWait, the thread calling the method will wait until the Runnable has been run in the event-thread before continuing.