BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 02-02-2009, 10:56 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2008
Location: Scotland
Model: None!
PIN: N/A
Carrier: Vodafone
Posts: 31
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Ui Threading issue?

Please Login to Remove!

Hi,

I have wrote some code to check whether the radio is active, if it is not then it activates the radio. I store this code in a static class and call it before trying to hit a web service to save the call timing out.

The problem that i am having is that the app hangs when i call the code and turn on the Radio, but it doesn't hang if i show a Dialog.Alert(); message. I'm wondering if this has something to do with execution on current Thread stopping and when i call Dialog.Alert it makes Ui thread active???

Code:
[code]
//This is in class extending MainScreen
if (Functions.checkConnection()) {
//Create thread to call web service
}

//This is in Functions Class
public final class Functions {
public static boolean checkConnection() {
if (RadioInfo.getState() == RadioInfo.STATE_OFF) {
Application.getApplication().invokeAndWait(new Runnable() {
public void run() {
Radio.activateWAFs(RadioInfo.WAF_3GPP);
}});
Dialog.alert("ON");//If this line is in works fine, if not then times out.
}
}
}
[code]
Thanks in advance
Offline  
Old 02-03-2009, 03:41 AM   #2 (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
Default

you have to synchronize on the event thread (or use invokelater) to show a dialog (or for any other ui interaction)
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 02-03-2009, 06:07 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2008
Location: Scotland
Model: None!
PIN: N/A
Carrier: Vodafone
Posts: 31
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks simon but why would showing a Dialog in the above code make the code run through successfully but if i don't show a Dialog it hangs?
Offline  
Old 02-03-2009, 07:03 AM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2008
Location: Scotland
Model: None!
PIN: N/A
Carrier: Vodafone
Posts: 31
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've narrowed the problem down, if i remove Radio.activateWAFs(RadioInfo.WAF_3GPP); the code works every time, the thread seems to hang on this line.

Any ideas why this would be happening?
Offline  
Old 02-03-2009, 07:54 AM   #5 (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
Default

i guess the method blocks, you should try to run it threaded
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 02-03-2009, 09:55 AM   #6 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2008
Location: Scotland
Model: None!
PIN: N/A
Carrier: Vodafone
Posts: 31
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Simon, I've finally solved it. I removed the invokeAndWait(); and added a Thread.sleep(100); to switch context to other active threads.
Offline  
Old 06-15-2009, 04:24 AM   #7 (permalink)
Knows Where the Search Button Is
 
Join Date: Jul 2008
Location: India
Model: 9000
Carrier: AirTel
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks FerminRomeroDeTorres , myself too faced the same..!
__________________
Praveen K
Offline  




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