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
New Developer
adisonjames
Posts: 44
Registered: ‎08-06-2009
My Device: Not Specified

Re: updating UI from system thread (ui engine accessed without holding the event lock)

[ Edited ]

Sorry to bring an old thread up, but this was very relevant to the issues I am facing.

 

I have two autostart modules (which work correctly, one for the logo and one that serves as the "initializer" autostart module) and when my UiApplication instantiates in the "initializer", I get a Singleton instance and then store that into the RuntimeStore, so that when the application is launched (so I have 3 entry points to the main(String[] a) method) I retrieve the RuntimeStore and everything works (Screen initialized in "initializer" is accessible as is the MessageConnection listener I add).

 

I also add a PhoneListener during the "initializer" and I have used the debugger in Eclipse to determine that everything inilializes and the proper methods are called.  When I simulate a call, the PhoneListener's callRecieved() and callIncoming() methods are invoked appropriately, but when I try to lock onto the eventLock I get a NullPointerException, from all of the following:

 

 

public void callConnected(int callId) {
			UiApplication.getUiApplication().invokeLater(new Runnable(){
				public void run(){
					//on event Thread
				}
			});
		}

 

public void callConnected(int callId) {
			myAppInstance.invokeLater(new Runnable(){
				public void run(){
					//on event Thread
				}
			});
		}

 

public void callConnected(int callId) {
            StaticUiApplication.invokeLater(new Runnable(){
                public void run(){
                    //on event Thread
                }
            });
        }

 

public void callConnected(int callId) {
			synchronized(Application.getEventLock()){//on event Thread
 } }

 

In each case, the application instance is giving me the NullPointerException.  How can I make use of GlobalEvents or the ApplicationManager to make this work.  I am thinking of not using eventLock all together, but would still like to troubleshoot my issue.

 

I have also tried to add the PhoneListener when the application is lauched instead of in the autostart module, but this is showing the same behavior.

 

Thank you for any help!

 

Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: updating UI from system thread (ui engine accessed without holding the event lock)

Listeners, like callConnected, are called in the context of the Application that is responsible for the listener, not your Application (even though it is your listener). 

 

So the best thing to do is to swap into your own application.  And the easiest way to do that is have the listener fire a GlobalEvent, have your application listen for that Event, and then your can run the code you need, in your own Process.  Global Events are really useful too, because you an pass Objects with them.  So you can extract what you want from the callConnected information, and pass all these details  to your Application for processing.

 

What Is - Global Events and Global Event Listeners
Article Number: DB-00145
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800620/What_Is...

New Developer
adisonjames
Posts: 44
Registered: ‎08-06-2009
My Device: Not Specified

Re: updating UI from system thread (ui engine accessed without holding the event lock)

Thank you for your help as always peter_strange. I will look into thtat article. Still is there a way to accomplish this as Blizzz has?

 

Thank you and will try to post some working code later!

Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: updating UI from system thread (ui engine accessed without holding the event lock)

Yes, it is possible to do that, but I would not recommend it.  The Global Event interface is a much cleaner approach. 

 

My rule is if you can do it with Global Events, do it.  Only if you can't, should you consider implementing your own context switch in this way.  The issue is not so much the context switch, it is actually to make use of this, you end up doing a lot of work that really belongs in your own application, in the callConnected method of the Phone application.  I don't like the thought that I could screw up the phone processing - that would make me really popular and my app would be ditched.  .

 

There are other related ways of doing the same thing, for example have a message queue in RuntimeStore, with notify/wait locking.  But Global Events provide this sort of service for free. 

New Developer
adisonjames
Posts: 44
Registered: ‎08-06-2009
My Device: Not Specified

Re: updating UI from system thread (ui engine accessed without holding the event lock)

I completely agree with not wanting to mess with the Phone process.

 

Just to follow up on simon_hain's post

 


if the listener is registered in another process, for example an autostart project (alternative entry point), you don't have an application object and need to use different approachs, see the knowledge base for some ideas.
other approaches include application manager or global events.


 

Just for reference, how would  a listener registered in another process be accessed?  Also to use the ApplicationManager would I be instantiating another Application process that would be housing the registered listeners?

Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: updating UI from system thread (ui engine accessed without holding the event lock)

Have a read of this Thread, which covers some background to this area.

 

http://supportforums.blackberry.com/t5/Java-Development/Multiple-running-instances-of-the-same-entry...

Contributor
arjuna
Posts: 48
Registered: ‎04-07-2011
My Device: 9550

Re: updating UI from system thread (ui engine accessed without holding the event lock)

I got same problem.

arjuna