简体   繁体   中英

I want to pause step counter sensor in android kotlin

   override fun onDestroy() {
    super.onDestroy()
    try {
        Log.e("TAG", "onDestroy:::Service==>>> " )
        val sm = getSystemService(SENSOR_SERVICE) as SensorManager
        sm.unregisterListener(this,sm.getDefaultSensor(Constant.SENSOR_TYPE))
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

Hello, I want to pause the step counting sensor whenever a user will press the stop button after that can't be counting steps.

But Currently in my code, I have called the onDestory method on the click stop button but still counting which means I can't pause the sensor for step counting. So can anyone answer me that is there any way to pause this case or is this not possible?

And also I have already tried to unregister the listener but still counting steps. For example, when I pause at 500 steps and after some time try to start steps counting I'm getting some other result like 800 or 1000 steps. This is my issue.

Can anyone help me and for more detail you can ask me in the comment box.

Maybe,other App is listening to StepCount sensor when you are walking

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM