3

I am using exactly this code in this example

http://android.themind-lab.com/post/2010/05/14/Dont-shake-my-phone!-How-to-detect-shake-motion-on-Android-phone.aspx

What should i include in MyMethod() to stop the listener and don`t wait for another shake after MyMethod() is called the first time?

Thanks

pingve
  • 67
  • 3
  • 6

2 Answers2

7

The line

sensorMgr.unregisterListener(this);

will make the system stop sending you onSensorChanged updates

Matt
  • 5,171
  • 7
  • 33
  • 42
  • Thank you this works for me too. But how am I able to `restart` the Listener? I implemented a pause button but I cant call my `registerListener` method to restart the Sensor. – Rod Kimble May 31 '16 at 13:19
2

finally found the answer:

this is not enough for unregister the listener, you also need to set your SensorEventListener to null

sensorMgr.unregisterListener(this);
msensorlistener = null;

this trick works very good,

hope it helps.

Amir Hossein Ghasemi
  • 7,952
  • 4
  • 43
  • 42