Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在这个例子中使用的正是这段代码
http://android.themind-lab.com/post/2010/05/14/Dont-shake-my-phone!-How-to-detect-shake-motion-on-Android-phone.aspx
我应该在 MyMethod() 中包含什么来停止侦听器并且在第一次调用 MyMethod() 之后不要等待另一次摇晃?
谢谢
线
sensorMgr.unregisterListener(this);
将使系统停止向您发送 onSensorChanged 更新
终于找到了答案:
这不足以取消注册监听器,您还需要将 SensorEventListener 设置为 null
sensorMgr.unregisterListener(this); msensorlistener = null;
这个技巧效果很好,
希望能帮助到你。