From 09d28fbd4af8c1e4c9df80a5f3c7dc19f41f8e56 Mon Sep 17 00:00:00 2001 From: milind Date: Mon, 27 Jan 2020 15:59:51 +0530 Subject: [PATCH] destroy handled --- .../matrixdev/gyrocardview/GyroCardView.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/gyrocardview/src/main/java/com/matrixdev/gyrocardview/GyroCardView.java b/gyrocardview/src/main/java/com/matrixdev/gyrocardview/GyroCardView.java index 83bc95b..78b5d4c 100644 --- a/gyrocardview/src/main/java/com/matrixdev/gyrocardview/GyroCardView.java +++ b/gyrocardview/src/main/java/com/matrixdev/gyrocardview/GyroCardView.java @@ -41,6 +41,7 @@ public class GyroCardView extends CardView { private Sensor sensor3; private float XOffset = 0.7f; private boolean isVerticalRotationEnabled; + private SensorEventListener2 sensorListener3; public GyroCardView(@NonNull Context context) { super(context); @@ -137,7 +138,7 @@ public void onAccuracyChanged(Sensor sensor, int i) { // sensorManager.registerListener(sensorListener, sensor2, SensorManager.SENSOR_DELAY_FASTEST); - sensorManager.registerListener(new SensorEventListener2() { + sensorListener3 = new SensorEventListener2() { @Override public void onFlushCompleted(Sensor sensor) { @@ -165,12 +166,22 @@ public void onSensorChanged(SensorEvent sensorEvent) { public void onAccuracyChanged(Sensor sensor, int i) { } - },sensor3,SensorManager.SENSOR_DELAY_FASTEST); + }; + sensorManager.registerListener(sensorListener3,sensor3,SensorManager.SENSOR_DELAY_FASTEST); } + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + try{ + sensorManager.unregisterListener(sensorListener3); + }catch (Exception e){ + e.printStackTrace(); + } + } -// @Override + // @Override // protected boolean getChildStaticTransformation(View child, Transformation t) { // // // apply transform to child view - child triggers this call by call to `invalidate()`