@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Sensor.isActive() == false) { Intent intent = new Intent(this, StartNewSensor.class); startActivity(intent); finish(); } else { setContentView(R.layout.activity_stop_sensor); button = (Button) findViewById(R.id.stop_sensor); addListenerOnButton(); } }