Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3112E10586 for ; Tue, 9 Jul 2013 17:00:11 +0000 (UTC) Received: (qmail 86583 invoked by uid 500); 9 Jul 2013 17:00:11 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 86508 invoked by uid 500); 9 Jul 2013 17:00:10 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 86501 invoked by uid 99); 9 Jul 2013 17:00:09 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Jul 2013 17:00:09 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id A102F889933; Tue, 9 Jul 2013 17:00:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ian@apache.org To: commits@cordova.apache.org Message-Id: <7342940ad5d44fa791108445a282759e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: CB-4081 Android Accelerometer- unregister for timeout Date: Tue, 9 Jul 2013 17:00:09 +0000 (UTC) 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 Authored: Fri Jul 5 10:13:32 2013 -0400 Committer: Ian Clelland 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); }