BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 02-02-2009, 10:56 AM   #1
FerminRomeroDeTorres
Knows Where the Search Button Is
 
Join Date: Aug 2008
Location: Scotland
Model: None!
PIN: N/A
Carrier: Vodafone
Posts: 31
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
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
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
FerminRomeroDeTorres
Knows Where the Search Button Is
 
Join Date: Aug 2008
Location: Scotland
Model: None!
PIN: N/A
Carrier: Vodafone
Posts: 31
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
FerminRomeroDeTorres
Knows Where the Search Button Is
 
Join Date: Aug 2008
Location: Scotland
Model: None!
PIN: N/A
Carrier: Vodafone
Posts: 31
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
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
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
FerminRomeroDeTorres
Knows Where the Search Button Is
 
Join Date: Aug 2008
Location: Scotland
Model: None!
PIN: N/A
Carrier: Vodafone
Posts: 31
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
pravipravi
Knows Where the Search Button Is
 
Join Date: Jul 2008
Location: India
Model: 9000
Carrier: AirTel
Posts: 29
Default

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



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Analog Panel AMP VOLT Current Ammeter Voltmeter Voltage Gauge 10A 50V DH-670 DC  picture

Analog Panel AMP VOLT Current Ammeter Voltmeter Voltage Gauge 10A 50V DH-670 DC

$12.99



Battery Tester DC 0-80V0-350A SOC AH VOLT AMP Capacity Tester Voltmeter Ammeter picture

Battery Tester DC 0-80V0-350A SOC AH VOLT AMP Capacity Tester Voltmeter Ammeter

$36.50



Mini Digital Voltmeter Ammeter DC 100V 10A Car LED Display Panel Amp Volt Tester picture

Mini Digital Voltmeter Ammeter DC 100V 10A Car LED Display Panel Amp Volt Tester

$10.49



AC 80-260V 0-100A LCD Digital Display Volt Watt Power Meter Voltmeter Ammeter picture

AC 80-260V 0-100A LCD Digital Display Volt Watt Power Meter Voltmeter Ammeter

$22.50



LCD Digital Multimeter Voltmeter Ammeter Ohmmeter Volt AC DC Tester Leads Meter picture

LCD Digital Multimeter Voltmeter Ammeter Ohmmeter Volt AC DC Tester Leads Meter

$9.95



Multifunction Digital Multimeter 1999 Counts AC/DC Volt Current Ohm Tester Meter picture

Multifunction Digital Multimeter 1999 Counts AC/DC Volt Current Ohm Tester Meter

$9.95







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