You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2013/07/09 19:00:09 UTC
git commit: CB-4081 Android Accelerometer- unregister for timeout
Updated Branches:
refs/heads/master 3f85d7bd6 -> afee2b4cb
CB-4081 Android Accelerometer- unregister for timeout
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/commit/afee2b4c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/tree/afee2b4c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/diff/afee2b4c
Branch: refs/heads/master
Commit: afee2b4cb066ba5c148e594363f599f4532f391b
Parents: 3f85d7b
Author: David Kemp <dr...@chromium.org>
Authored: Fri Jul 5 10:13:32 2013 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Tue Jul 9 12:59:19 2013 -0400
----------------------------------------------------------------------
src/android/AccelListener.java | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/blob/afee2b4c/src/android/AccelListener.java
----------------------------------------------------------------------
diff --git a/src/android/AccelListener.java b/src/android/AccelListener.java
index 1c43770..ff931e3 100755
--- a/src/android/AccelListener.java
+++ b/src/android/AccelListener.java
@@ -59,6 +59,13 @@ public class AccelListener extends CordovaPlugin implements SensorEventListener
private CallbackContext callbackContext; // Keeps track of the JS callback context.
+ private Handler mainHandler=null;
+ private Runnable mainRunnable =new Runnable() {
+ public void run() {
+ AccelListener.this.timeout();
+ }
+ };
+
/**
* Create an accelerometer listener.
*/
@@ -155,20 +162,22 @@ public class AccelListener extends CordovaPlugin implements SensorEventListener
}
// Set a timeout callback on the main thread.
- Handler handler = new Handler(Looper.getMainLooper());
- handler.postDelayed(new Runnable() {
- public void run() {
- AccelListener.this.timeout();
- }
- }, 2000);
+ stopTimeout();
+ mainHandler = new Handler(Looper.getMainLooper());
+ mainHandler.postDelayed(mainRunnable, 2000);
return this.status;
}
-
+ private void stopTimeout() {
+ if(mainHandler!=null){
+ mainHandler.removeCallbacks(mainRunnable);
+ }
+ }
/**
* Stop listening to acceleration sensor.
*/
private void stop() {
+ stopTimeout();
if (this.status != AccelListener.STOPPED) {
this.sensorManager.unregisterListener(this);
}