BlackBerry Forums Support Community

Closed Thread
LinkBack Thread Tools
Old 10-31-2007, 08:12 AM   #1 (permalink)
CrackBerry Addict
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb Getting the EventLock from outside the Application

Please Login to Remove!

I found something interesting today.

My application has a FolderListener registered on the mail store and is alerted when a new mail arrives.
If it is a certain mail i want to update the UI in my application and i have to possibilities to do so:

1. synchronized (UiApplication.getEventLock())
2. invokeLater(new Runnable()...

The first option leads to a Ui accessed without holding the eventlock exception. The second option freezes the device.

As i discovered UiApplication.getEventLock() gives you the eventlock of the calling application, in my case the folderlistener, which can not provide the eventlock.

My solution is to provide a method in the main application:
public Object getApplicationEventLock() {		
	return getAppEventLock();
i now synchronize on this method in my screens and other UI elements:
synchronized (app.getApplicationEventLock()){
I thought this could be helpful for anybody stumbling upon a similar problem.
java developer, Devinto, hamburg/germany
Old 10-31-2007, 09:27 AM   #2 (permalink)
Talking BlackBerry Encyclopedia
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts

that is helpful, I find the invokeLater doesn't cause the problem you see, but is not the most efficient or elegant solution. thanks for the tip

Copyright 2004-2016
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.