android getting data from UIThread
<p>I'm trying to send android data to arduino using <code>Bluetooth</code>.My gui contains a <code>SeekBar</code> and accelerometer readings.All the <code>Sockets</code> are successfully formed and every thing is working fine if I write data to the <code>OutputStream</code> of the <code>Socket</code> from <code>onSeekBarChanged()</code> method so that data will be transferred to arduino whenever I change the SeekBar.</p>

<pre><code> public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        if(seekBar.getId() == R.id.seekBar)
        {
            speed.setText(String.valueOf(progress));
            String outputData = String.valueOf(progress)+",";
            try
            {
            streams.write(outputData.getBytes());//writes data to OutputStream of Socket
            }catch (Exception e){
                Log.d("RTR","Sockets not yet formed");
            }

        }
    }
</code></pre>

<p>The problem is I need to send <code>Accelerometer</code> data continuously along with <code>SeekBar</code> current value.So I tried to write to <code>OutputStream</code> of the <code>Socket</code> from <code>onSensorChanged(SensorEvent event)</code> method of the accelerometer.<code>Result:Program not responding.</code></p>

<pre><code>public void onSensorChanged(SensorEvent event) {

        if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
        {
            float accXYZ[] = event.values;

            float accX = accXYZ[0];
            float accY = accXYZ[1];
            float accZ = accXYZ[2];

            x.setText(String.format("%.2f",accX));
            y.setText(String.format("%.2f",accY));
            z.setText(String.format("%.2f",accZ));

            String outputData = x.getText().toString()+","+speed.getText().toString()+";";

            try{
                  streams.write(outputData.getBytes());
            }catch (Exception e){
                //Log.d("RTR","X");
            }

        }
    }
</code></pre>

<p>I understand that this is too much overload on the <code>UI Thread</code>.I think I should create a <code>new Thread</code> with an infinite loop in <code>run()</code> method to send the data continuously.How can I send the accelerometer and SeekBar data to this new Thread continuously.</p>

<p>Or should I collect UIThread's accelerometer and SeekBar's data from this new thread.</p>

<pre><code>In Short, how do I get data from UIThread to this new Thread.
</code></pre>

<p>Please provide all possible solutions you're aware of for my problem and any complications with my current procedure.</p>
