onSensorChanged and the UI Thread
<p>I am using the accelerometer to know when my phone positioned flat, face up. When this happens I turn on the speakerphone, which works but the speakerphone button light to notify the user does not light up. I'm not sure how to update the changes on the UI thread. Any help would be fantastic.</p>

<pre><code>am = (AudioManager)getSystemService(Context.AUDIO_SERVICE); 
sm = (SensorManager)getSystemService(SENSOR_SERVICE);
sensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
sm.registerListener(this,sm. getDefaultSensor(Sensor.TYPE_ACCELEROMETER),SensorManager.SENSOR_DELAY_UI);

static SensorManager sm = null;
    static Sensor sensor;
    AudioManager am;

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {}

@Override
public void onSensorChanged(SensorEvent event) {
    synchronized(this)
    {
        if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
        {
            //flat face up
            if(event.values[0] &lt; 2 &amp;&amp; event.values[0] &gt; -2 &amp;&amp;
               event.values[1] &lt; 2 &amp;&amp; event.values[1] &gt; -2 &amp;&amp;
               event.values[2] &gt; 8.5 &amp;&amp; am.isSpeakerphoneOn() == false &amp;&amp;
               imageButtonStateHorizontal == 1 &amp;&amp; imageButtonStateMaster == 1)
            {
                setStateHorizontalSpeakerphone = true;
            }

            //flat face up
            if(event.values[0] &lt; 2 &amp;&amp; event.values[0] &gt; -2 &amp;&amp;
               event.values[1] &lt; 2 &amp;&amp; event.values[1] &gt; -2 &amp;&amp;
               event.values[2] &gt; 8.5 &amp;&amp; am.isSpeakerphoneOn() == false &amp;&amp;
               imageButtonStateHorizontal == 1 &amp;&amp; imageButtonStateMaster == 0 &amp;&amp;
               setStateHorizontalSpeakerphone == false)
            {                               
                setStateHorizontalSpeakerphone = true;  
                am.setSpeakerphoneOn(true);
            }
        }
    }
}
</code></pre>

<p>after all that when I end my service I registered the sensor.</p>
