Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get the ShakeDetector to stop #14

Open
timbremer opened this issue Jun 11, 2016 · 5 comments
Open

Can't get the ShakeDetector to stop #14

timbremer opened this issue Jun 11, 2016 · 5 comments

Comments

@timbremer
Copy link

I put sd.stop(); in onPause(), onDestroy(), and onBackPressed() but when I leave the application and shake the device on my homescreen for example it still performs the specified action.

@slm
Copy link

slm commented Aug 22, 2016

👍

@Jaystiqs
Copy link

Use
sd.stop();
sensorManager.unregisterListener(sd);

in your onDestroy Override method

@the-rebooted-coder
Copy link

I put sd.stop(); in onPause(), onDestroy(), and onBackPressed() but when I leave the application and shake the device on my homescreen for example it still performs the specified action.

Solved for me though!
Thanks!

@Jaystiqs
Copy link

Jaystiqs commented Nov 21, 2020 via email

@aydinozkan
Copy link

@timbremer I know I'm late to the party but this may help others. I had the same issue and solved it by moving the start process of ShakeDetector to onResume instead of onCreate.

override fun onResume() {
        shakeDetector.start(sensorManager)

        super.onResume()
    }

And I stop the ShakeDetector and unregister listeners of SensorManager when the activity gets paused.

override fun onPause() {
        if (BuildConfig.DEBUG) {
            shakeDetector.stop()
            sensorManager.unregisterListener(shakeDetector)
        }

        super.onPause()
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants