Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants