BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 02-27-2006, 03:57 PM   #1
lorennorman
Knows Where the Search Button Is
 
Join Date: Jan 2006
Model: 7520
Posts: 22
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, 11:23 PM   #2
fbrimm
Thumbs Must Hurt
 
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Posts: 144
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, 09:10 AM   #3
lorennorman
Knows Where the Search Button Is
 
Join Date: Jan 2006
Model: 7520
Posts: 22
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, 03:02 PM   #4
lorennorman
Knows Where the Search Button Is
 
Join Date: Jan 2006
Model: 7520
Posts: 22
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



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


Digital Ohmmeter LCD Audio Impedance Test Meter Speaker Voice Resistor System picture

Digital Ohmmeter LCD Audio Impedance Test Meter Speaker Voice Resistor System

$83.60



IMPEDENCE MATCHING TRANSFOMER BNC F-BNC F, 50 OHM TO 75 OHM, 20-1100 MHZ picture

IMPEDENCE MATCHING TRANSFOMER BNC F-BNC F, 50 OHM TO 75 OHM, 20-1100 MHZ

$28.00



ESI IMPEDANCE BRIDGE MODEL 250-DA -- Working, Pristine picture

ESI IMPEDANCE BRIDGE MODEL 250-DA -- Working, Pristine

$140.00



Zareba Low Impedance Electronic Fence Controller 2 Miles picture

Zareba Low Impedance Electronic Fence Controller 2 Miles

$20.00



UFI Checktrode 1089 MKIII Impedance Meter + Case Electrode Tester Total Contact picture

UFI Checktrode 1089 MKIII Impedance Meter + Case Electrode Tester Total Contact

$169.99



Digital Handheld Megohmmeter Insulation Resistance Tester Audio Impedance Speake picture

Digital Handheld Megohmmeter Insulation Resistance Tester Audio Impedance Speake

$76.38







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