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:
Code:
public Object getApplicationEventLock() {		
	return getAppEventLock();
}
i now synchronize on this method in my screens and other UI elements:
Code:
synchronized (app.getApplicationEventLock()){
}
I thought this could be helpful for anybody stumbling upon a similar problem.
__________________
java developer, Devinto, hamburg/germany
Offline  
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
Default

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
Offline  




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