Welcome!

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

Reply
Highlighted
New Developer
Posts: 9
Registered: ‎05-04-2009
My Device: Not Specified

Error trying to pushScreen inside a thread

Hi,

 

We are trying to push the screen PopUpColeta (below) inside the TimeAuditor class which extends Thread (details below) but we get the following exception: "java.lang.IllegalStateException: UI engine accessed without holding the event lock"

 

public class PopUpColeta extends PopupScreen implements KeyListener

 

public class TimeAuditor extends Thread

 

UiApplication.getUiApplication().pushScreen(popUpColeta)

 

For some reason the pushScreen command above works fine when we place it inside the MainScreen.

 

We are using BlackBerry Component Pack 4.5.0

 

Thanks!

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Error trying to pushScreen inside a thread

[ Edited ]

Place the pushScreen or popScreen inside of a Runnable and pass this Runnable to UiApplication.invokeLater()

 

Something like this:

/** * Stop the status display */ private void stopStatusDisplay() { if (m_statusDisplay != null){ m_app.invokeLater(new Runnable() { public void run()

{ m_statusDisplay.close(); m_statusDisplay = null; } }); } }

 

 

Note that I'm storing an instance of my application (m_app), since you can't always rely on UiApplication.getApplication(), depending on the context of the thread that is calling the UI.

 

Message Edited by RexDoug on 07-25-2009 10:47 AM
Developer
Posts: 88
Registered: ‎07-11-2009
My Device: Not Specified

Re: Error trying to pushScreen inside a thread

RexDoug:  In what context can you not rely on the UiApplication.getApplication() method?
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Error trying to pushScreen inside a thread

This static method will return the current UiApplication, which may not be your application in certain circumstances.

 

For example, your app is called form a Message listener or Phone listener. In this case, the application context belongs to the calling app, not yours.