0

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

marcel
  • 696
  • 1
  • 10
  • 17

1 Answers1

0

I was under the impression that system.out.println messages are "lost" on the Android platform and never reach any debug window in Eclipse. Instead you should use the Log class to produce Logcat messages.

See:

Why doesn't "System.out.println" work in Android?

Edit: Ah, I just noticed that you're also calling a method setTemperature() to update your TextView, but I can't seem to find that method in your code listing. So at this stage, I'm not sure if your problem is that you're expecting system.out.println to produce something in Logcat, or if something's wrong with your setTemperature() method.

Have you tried using a breakpoint in Debug mode to see if the handler is being called? As far as I can tell at a glance, your thread code seems OK.

Community
  • 1
  • 1
Trevor
  • 10,903
  • 5
  • 61
  • 84
  • Hmm, I try it with Log.d(...) , and Debug Mode but nothing. It seems that handleMessage() is never called. The setTemperature() fkt. is not important(but I also change this part). Damm I don't know where the mistake is.. – marcel May 04 '11 at 18:17
  • I found my mistake , I start the thread with .run not with .start() – marcel May 05 '11 at 13:24