Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicate Android sensor listener registrations #61330

Merged
merged 1 commit into from
May 23, 2022

Conversation

madmiraal
Copy link
Contributor

Currently, on Android, sensor listeners are being registered twice first: in initializeGodot(), which is called by onCreate():

mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
mGravity = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_GAME);
mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME);
mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME);

and a second time in onResume():
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_GAME);
mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME);
mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME);

As defined in the Android activity lifecycle, onResume() always follows onCreate() so the listeners are being registered twice for no reason.

They're being unregistered in onPause():

mSensorManager.unregisterListener(this);

Therefore, they need to be included in onResume(). However, we can safely remove them from initializeGodot().

Note: The early registration prevented #22644 from working.

Can be cherry-picked onto 3.x.

@akien-mga akien-mga added the cherrypick:3.x Considered for cherry-picking into a future 3.x release label May 23, 2022
@akien-mga akien-mga added this to the 4.0 milestone May 23, 2022
@akien-mga akien-mga merged commit 9b3dd5e into godotengine:master May 23, 2022
@akien-mga
Copy link
Member

Thanks!

@madmiraal madmiraal deleted the android-duplicate-register branch May 23, 2022 20:00
@akien-mga
Copy link
Member

Cherry-picked for 3.5.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants