title: Starting and stopping process with buttons
body: <p>I have an accelerometer app I am developing for Android, and I want to start and stop the activity with a "start" and "stop" button. I am having trouble implementing the buttons in the code itself and I am looking for some help. Here is my main java file.</p>
  
  <pre><code>package com.*****.accelo;
  
  
  
  import android.app.Activity;
  
  import android.content.Context;
  
  import android.hardware.Sensor;
  
  import android.hardware.SensorEvent;
  
  import android.hardware.SensorEventListener;
  
  import android.hardware.SensorManager;
  
  import android.os.Bundle;
  
  import android.widget.TextView;
  
  import android.widget.Button;
  
  import android.view.View.OnClickListener;
  
  
  
  public abstract class AcceloActivity extends Activity implements SensorEventListener,   
  OnClickListener  {
  
  
  
  TextView textViewX, textViewY, textViewZ, textViewError;
  String blank;
  Button buttonStop, buttonStart;
  
  StringBuilder builderx = new StringBuilder();
  StringBuilder buildery = new StringBuilder();
  StringBuilder builderz = new StringBuilder();
  
  
  
  
  public void onCreate(Bundle savedInstanceState){
  
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.main);
  
      textViewError = (TextView) findViewById(R.id.textViewError);
      textViewX = (TextView) findViewById(R.id.textViewX);
      textViewY = (TextView) findViewById(R.id.textViewY);
      textViewZ = (TextView) findViewById(R.id.textViewZ);
      buttonStart = (Button) findViewById(R.id.buttonStart);
      buttonStop = (Button) findViewById(R.id.buttonStop);
  
       //Button listener
      buttonStart.setOnClickListener(this);
      buttonStop.setOnClickListener( this);
  
  
  
  
      SensorManager manager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
  
      Sensor accelerometer = manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
  
          if(!manager.registerListener(this, accelerometer, 
  SensorManager.SENSOR_DELAY_UI)){
  
  
  
          }
  
  textViewX.setText(blank);
  textViewY.setText(blank);
  textViewZ.setText(blank);
  }
  
  
  
  
  public void onAccuracyChanged(Sensor sensor, int accuracy) {
  
  
  
  }
  
  
  
  public void onSensorChanged(SensorEvent event) {
  
      builderx.setLength(0);
      buildery.setLength(0);
      builderz.setLength(0);
  
      builderx.append("X:  " + event.values[0]);
      buildery.append("Y: "+  event.values[1] );
      builderz.append("Z: " + event.values[2]);
  
      textViewX.setText(builderx.toString());
      textViewY.setText(buildery.toString());
      textViewZ.setText(builderz.toString());
      textViewError.setText(blank);
  
  }
  </code></pre>
  
  <p>Thanks in advance!</p>