[Help] My Merge Fellas Mod causes an "unlimited shake" event loop.

kimakiwe

New member
Jun 23, 2025
1
0
1
Hi everyone,

This is my first post here, so please be gentle! I'm a student trying to learn Android development by building a small personal game project.

I'm trying to implement a feature where the player can shake their phone to trigger an action. I've created a separate module for this (which I call the "Merge Fellas Mod" internally, as it's for my project "Merge Fellas").

The problem is, it's causing an "unlimited shake" bug. After the very first shake, the shake event gets triggered continuously in a loop, flooding the Logcat and eventually making the app unresponsive. It feels like the sensor is stuck.

I've tried the common solutions like using a timestamp to create a cooldown period between shakes, but it seems I'm implementing it wrong. I'm pretty sure it's a simple logic error that a more experienced developer could spot easily.

To keep this post clean, I've put my simplified `ShakeDetectorModule.kt` code into a Google Doc. It includes the listener implementation and the logic I'm using.

You can see the code snippet here:
https://docs.google.com/document/d/1AOc1N7l1CGM7gt2wD2L_tk6fjbtVSIIYHodjKcW2h7s/edit?usp=sharing

Could anyone please take a quick look and give me a pointer on what I'm doing wrong? Is there a better or more standard way to handle single shake gestures without them firing infinitely?

Thanks so much in advance for any advice!
 
Welcome to Android Central! I moved this from the Ask A Question forum to the Software Development forum for more appropriate traffic. However, be advised that we don't get that many developers to discuss things like this. Good luck!
 

Forum statistics

Threads
955,572
Messages
6,965,286
Members
3,163,337
Latest member
AnonymousMRFR