title: OnSensorChanged Thread
body: <p>I need to do a lot of work in method onSensorChanged so my App is freezing.
  I tryied to create thread in method OnSensorChanged. It helps a little but creating new thread manytimes per secound is not the best way I think. What should I do?</p>
  
  <p>I created my own sensorService which extends Service and implements SensorEventListener.</p>
  
  <pre><code>@Override
  public void onSensorChanged(SensorEvent event) {
      Thread w = new Thread(new Worker(event));
      w.start();
  
  }
  
  class Worker implements Runnable{
      SensorEvent event;
      Worker(SensorEvent event){
          this.event=event;
      }
      @Override
      public void run() {
          if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
              accelerometerData(event);
          }
          if(event.sensor.getType()==Sensor.TYPE_GRAVITY){
              gravityData(event);
          }
          if(event.sensor.getType()==Sensor.TYPE_LINEAR_ACCELERATION){
              linearAccelerometerData(event);
          }
      }
      private void linearAccelerometerData(SensorEvent event) {
          expensiveWork();
          Intent intent = new Intent("SensorService");
          intent.putExtra("data",data)            LocalBroadcastManager.getInstance(SensorService.this).sendBroadcast(intent);
      }
  
      private void accelerometerData(SensorEvent event){  
          expensiveWork2();
          Intent intent = new Intent("SensorService");
          intent.putExtra("data",data)    
          LocalBroadcastManager.getInstance(SensorService.this).sendBroadcast(intent);
      }
  }
  </code></pre>
  
  <p>Can I start service on its own thread? Or create just one thread and give him the work?</p>