From b20f7e7302a263202254200b1920049c61c9d01c Mon Sep 17 00:00:00 2001 From: fysx Date: Wed, 22 Oct 2014 11:26:52 +0200 Subject: [PATCH] Stop the vibrator when the app is paused (e.g. when device is switched off or app goes in background) --- src/org/love2d/android/GameActivity.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/org/love2d/android/GameActivity.java b/src/org/love2d/android/GameActivity.java index 3946e6bd..a1cb5e42 100644 --- a/src/org/love2d/android/GameActivity.java +++ b/src/org/love2d/android/GameActivity.java @@ -56,6 +56,20 @@ public class GameActivity extends SDLActivity { getWindowManager().getDefaultDisplay().getMetrics(metrics); } + @Override + protected void onDestroy() { + Log.d("GameActivity", "Cancelling vibration"); + vibrator.cancel(); + super.onDestroy(); + } + + @Override + protected void onPause() { + Log.d("GameActivity", "Cancelling vibration"); + vibrator.cancel(); + super.onPause(); + } + public static String getGamePath() { Log.d ("GameActivity", "called getGamePath(), game path = " + gamePath); return gamePath; @@ -66,7 +80,6 @@ public class GameActivity extends SDLActivity { } public static void vibrate (double seconds) { - Log.d ("GameActivity", "vibrating for " + seconds + " seconds"); vibrator.vibrate((long) (seconds * 1000.)); }