Skip to content

Commit

Permalink
fix(android): accelerometer logs warnings on exit
Browse files Browse the repository at this point in the history
Fixes TIMOB-28272
  • Loading branch information
jquick-axway authored and sgtcoolguy committed Dec 14, 2020
1 parent 08f917d commit e10b6e6
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.KrollRuntime;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.util.TiSensorHelper;

Expand All @@ -28,6 +29,22 @@ public class AccelerometerModule extends KrollModule implements SensorEventListe
public AccelerometerModule()
{
super();

// Set up a listener to be invoked when the JavaScript runtime is about to be terminated/disposed.
KrollRuntime.addOnDisposingListener(new KrollRuntime.OnDisposingListener() {
@Override
public void onDisposing(KrollRuntime runtime)
{
// Remove this listener from the runtime's static collection.
KrollRuntime.removeOnDisposingListener(this);

// Unregister the sensor listener.
if (accelerometerRegistered) {
TiSensorHelper.unregisterListener(Sensor.TYPE_ACCELEROMETER, AccelerometerModule.this);
accelerometerRegistered = false;
}
}
});
}

@Override
Expand Down

0 comments on commit e10b6e6

Please sign in to comment.