简体   繁体   English

我想在 android kotlin 中暂停计步传感器

[英]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.但目前在我的代码中,我在点击停止按钮上调用了 onDestory 方法,但仍在计数,这意味着我无法暂停传感器进行计步。 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.例如,当我在 500 步处暂停并尝试开始计算步数时,我会得到一些其他结果,例如 800 或 1000 步。 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也许,当你走路时,其他 App 正在监听 StepCount 传感器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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