Hallo,
I'am new with threading and so I read an article/tutorial about it... tutorial
My goal is to update the textview in the gui from the thread...
public class recorderThread extends Thread {
public boolean recording = true; //variable to start or stop recording
public int frequency; //the public variable that contains the frequency value "heard", it is updated continually while the thread is running.
int numSamples;
AudioRecord recorder;
int numCrossing,p;
short audioData[];
int bufferSize;
private Handler parentHandler;
public recorderThread (Handler parentHandle ) {
this.parentHandler = parentHandle;
}
@Override
public void run() {
doingSuff();
Message msgn = new Message() ;
msgn.arg1 = frequency;
/* Sending the message */
parentHandler.sendMessage(msgn);
} //while recording
}//run
}//recorderThread
And the activity
public class sonicDistance extends Activity {
recorderThread rthread ;
static TextView freq;
static TextView duration;
static TextView samplerate;
private static TextView temperature;
static TextView measuredDistance;
private static TextView measuredTimeDiff;
public static TextView measuredFrequenz;
private CustomDialog myfreqDialog;
static double startTime = 0;
static double endTime = 0;
private static float c_propagation = 0;
private static float choosen_temperature = 20;
static double messureFreq = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
freq =((TextView) findViewById(R.id._freqOfTone));
duration =((TextView) findViewById(R.id.duration));
samplerate = ((TextView) findViewById(R.id.Samplerate));
temperature = ((TextView) findViewById(R.id.temperature));
measuredFrequenz = ((TextView) findViewById(R.id._messuredFrequenz));
measuredDistance = ((TextView) findViewById(R.id.distance));
measuredTimeDiff = ((TextView) findViewById(R.id._timediff));
rthread = new recorderThread(myHandler);
rthead.run();
}
public Handler myHandler = new Handler(){
public void handleMessage(Message msg) {
System.out.println(msg.arg1);
setTemperature(Float.valueOf((String)msg.obj));
System.out.println("test" + Float.valueOf((String)msg.obj));
}
};
@Override
protected void onResume(){
super.onResume();
}
}
There is no system.out in the activity from the handler. I think this one is never called.
I don't know where is my mistake..
thank You