BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 02-27-2006, 02:57 PM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Jan 2006
Model: 7520
Posts: 22
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Thread Communication

Please Login to Remove!

I need to create a separate thread to make an HTTP request. The parent thread can easily poll the daughter thread and update its own members (graphical elements) but the daughter thread can't update those members itself, despite the fact that the same object is visible (the daughter thread is an inner class of the parent thread.)

What gives? It seems like when i try to refer back to the parent thread's members, the daughter thread just locks up and never makes the HTTP request at all, but i'm not getting error messages or anything. Polling is really out of the question, when the http request completes, i need to tell the user about the results. Any hints, developer community?
Offline  
Old 02-27-2006, 10:23 PM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Posts: 144
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

lorennorman,

I had a similar application, only using a socket connection instead of http.

I could never figure out how to manipulate the parent thread directly from the daughter thread. The best I could do was to pop/push the parent GUI thread to force it to redisplay using the new data that has been received.

Someone suggested invalidating the parent GUI, but that didn't work for my GUI app.

I'd love to learn if there is a better/proper way to do it.

fbrimm
Offline  
Old 02-28-2006, 08:10 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Jan 2006
Model: 7520
Posts: 22
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, i have a well known screen navigator class that gives me static access to the UiApplication object, so i'll mess with the pop/push method you mentioned and see if that enlightens me on the design a bit.

Does RIM just have trouble with Threads, or are we doing something wrong (he casually asks the peanut gallery...)?
Offline  
Old 02-28-2006, 02:02 PM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Jan 2006
Model: 7520
Posts: 22
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Solved! You need to use the invokeLater(Runnable) static method from the Application class. The daughter thread can call a function in the parent thread that modifies its own members in a subthread (runnable) passed to that function. I'll show you:

daughter thread, in run method can call this function in parent thread:

private void updateText(final byte[] data)
{
Application.getApplication().invokeLater(new Runnable() {
public void run() {
_infoField.setText("Received "+ data.length +" bytes of text.");
_textField.setText(new String(data));
}
});
}

and it will update the appropriate member Fields whenever the dispatching thread becomes available, as opposed to crashing with IllegalStateException, or whatever it does without the invokeLater() call.
Offline  
Closed Thread


Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





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