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
Developer
skynetchris
Posts: 39
Registered: ‎07-18-2008
My Device: Not Specified
Accepted Solution

invokeLater/HTTP

Hi all,

 

I have an application which spawns a thread to test connectivity such as HTTP, GPS and Radio status.

 

Everything works excepet when it gets to the HTTP check, where it throws an error complaining the event dispatcher is being blocked:

 

case Characters.LATIN_SMALL_LETTER_T: debugThread debug = new debugThread(); UiApplication.getUiApplication().invokeLater(debug);

 

private class debugThread extends Thread {
public void run(){

 

connection = (StreamConnection)Connector.open(_hostName+"/b.php?gprs="+gprsStrength+"&IMEI="+imei);

httpConn = (HttpConnection)connection; int response = httpConn.getResponseCode(); if (response != HttpConnection.HTTP_OK) { debugDump.insert("HTTP\t...none\n"); } else { debugDump.insert("HTTP\t...OK\n"); }...

 

 

Why would this cause a blocking issue with the GUI??

 

Please use plain text.
Developer
peter_strange
Posts: 19,604
Registered: ‎07-14-2008
My Device: Not Specified

Re: invokeLater/HTTP

The invoke Later is used to invoke processing on the Event Thread, so you are, in fact starting your Thread processing on the Event Thread.

 

Replace:

UiApplication.getUiApplication().invokeLater(debug);

with

debug.start();

 

Now debug is running in the background.  Note that if the

debugDump.insert("..);

statements attempt to update the UI, they will have to run using the Event Thread, otherwise you will get an IllegalStateException.

Please use plain text.
Developer
skynetchris
Posts: 39
Registered: ‎07-18-2008
My Device: Not Specified

Re: invokeLater/HTTP

Spot on, thanks peter =)
Please use plain text.