2

I am trying to develop a BlackBerry app for a Storm2. I am facing a problem when trying to update a LabelField from a different instance of the app.

The program is working fine without updating this LabelField, but when I tried to add the code to update the text, it becomes unresponsive after the "settext" line.

Am I missing something?

public class AgentTrackerScreen extends MainScreen
{
    public static LabelField _outputText;
    ...
}

public class BtService implements Runnable
{
    ...
    public void run() 
    {
        AgentTrackerScreen._outputtext.settext(
            "Something: " + btListener.vecDevices.size());
    }
    ...
}
Michael Donohue
  • 11,776
  • 5
  • 31
  • 44
RA Student
  • 31
  • 3
  • Try splitting the code inside your `run()` method into two lines (first line creates the string and second line uses the string in `settext`) to see whether the problem is with `settext` or with `btListener.vecDevices.size()`. – MusiGenesis Feb 08 '11 at 15:34
  • I have already tried that. btListener.vecDevices.size() is working fine; I think settext is the one that have issues. – RA Student Feb 08 '11 at 15:43

2 Answers2

3

You must make all user interface modifications on the event thread, or else lock the user interface before doing it. See BlackBerry UI Threading Basics for details.

(BTW, this is a common requirement in many user interface systems. Swing in Java SE has this requirement. So does WPF on Windows.)

Dhruv
  • 1,129
  • 2
  • 13
  • 32
Eric Giguere
  • 3,495
  • 15
  • 11
1

Use either:

  • invokeAndWait(Runnable r)
  • invokeLater(Runnable r)
  • synchronize on UiApplication.getEventLock()
Todd
  • 438
  • 1
  • 3
  • 10