Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Update a screen on the Main Event Thread

by Retired ‎02-16-2010 02:57 PM - edited ‎09-16-2010 03:42 PM (11,231 Views)



This article applies to the following:

  • BlackBerry® wireless devices based on Java™
  • BlackBerry Java Development Environment (JDE)



Making changes to the screen currently displayed in a BlackBerry application requires you to put a runnable object into this application's event queue. This can be performed by calling the invokeLater() or invokeAndWait() methods. Depending on the nature of the change being made, the screen may have to be repainted. Calling the invalidate() method causes the specified screen to be repainted.


Whenever possible, the invokeLater () method should be used for screen changes. This adds the screen change to the application event queue for execution. The invokeAndWait() method forces the code to be executed right away, halting other processing. The invokeAndWait() method can be used when screen updates must occur in a timely fashion, such as when performing an animation. Calling invokeLater() repeatedly in rapid succession causes the event queue to overflow and throw an exception.


Note: You should only use these methods when necessary, and only for the smallest quantity of code necessary.


Alternatively, a worker thread can synchronize with the event lock (returned by Application.getEventLock()) to verify serialized access to the user interface (UI).


Note: You should only hold this lock for very short periods of time.


The code on the event thread should not block or execute for long periods of time; the system will not dispatch messages, and the event queue can overflow. You can use background threads for long processing.


The code sample below gives an example of calling the invokeLater() method.



UiApplication.getUiApplication().invokeLater (new Runnable() {
    public void run()
        //Perform screen changes here.

        //Calling invalidate() on your screen forces the paint
        //method to be called.


by Developer
on ‎08-10-2011 12:26 AM

Frankly, the example seems to be quite useless. invalidate schedules a repaint on the event queue anyway, so scheduling an action that queues another one looks like an unnecessary recursion to me. Please correct me if I'm wrong - I have no access to RIM's source code and thus cannot verify my statement.

Users Online
Currently online: 18 members 2,781 guests
Please welcome our newest community members: