简体   繁体   English

如何停止加速计传感器

[英]How to stop accelerometer sensor

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 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? 我应该在MyMethod()中包含什么来阻止听众并且在第一次调用MyMethod()之后不要等待另一次摇动?

Thanks 谢谢

The line 这条线

sensorMgr.unregisterListener(this); sensorMgr.unregisterListener(本);

will make the system stop sending you onSensorChanged updates 将使系统停止发送onSensorChanged更新

finally found the answer: 终于找到了答案:

this is not enough for unregister the listener, you also need to set your SensorEventListener to null 这对于取消注册侦听器是不够的,您还需要将SensorEventListener设置为null

sensorMgr.unregisterListener(this);
msensorlistener = null;

this trick works very good, 这招很好用,

hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM