Android Studio Shake Event Listener

I have created a Shake Event Listener app in Android Studio. After I install the app on my phone, the event responds properly, but the problem is that when I leave the app, it still keeps track of the shock. Can someone help me how to stop it when I'm out of the app …