In my activity, i monitor a sensor, with "onSensorChanged" method.

I start monitoring the sensor when a button in that activity is pushed (in the "onClick" method).

I register and unregister the listening in the onPause and onResume methods.

Here is the code:

public void onCreate(Bundle savedInstanceState) {
  //Here i set "mySensor"
}

public void onClick(View view){
  sensorManager.registerListener(this, mySensor, SensorManager.SENSOR_DELAY_FASTEST);
}

protected void onPause() {
  sensorManager.unregisterListener(this, mySensor);
}

protected void onResume() {
  sensorManager.registerListener(this, mySensor, SensorManager.SENSOR_DELAY_FASTEST);
}

public final void onSensorChanged(SensorEvent event) {
  //do things
}

The problem is that, when there is an screen orientation change, the monitoring stops, the things i do within "onSensorChanged" stop until i press the button again.

I have been reading, and it seems that when the screen orientation changes, my activity is destroyed and recreated, but i would like the monitoring of the sensor not stopping during that process.

How can i keep the monitoring? i think it must be done using the Bundle, but im not sure.

Thanx.

没有正确的解决方案

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top