简体   繁体   English

如何正确配置 SensorManager

[英]How to correctly dispose a SensorManager

Hey, I am using a SensorManager in my Android application.嘿,我在我的 Android 应用程序中使用 SensorManager。 I understand that I have to dispose it in some way once the application is closed, because otherwise it would continue to listen to changes.我知道一旦应用程序关闭,我必须以某种方式处理它,否则它会继续监听更改。 So I tried the following:所以我尝试了以下方法:

@Override
    public void onDestroy()
    {
        manager.unregisterListener(temp);
    }

(when temp was an instance of TempListener extends SensorEventListener, and it was added to the SensorManager manager with manager.registerListener(temp...)). (当 temp 是 TempListener 的实例扩展 SensorEventListener 时,它通过 manager.registerListener(temp...) 添加到 SensorManager 管理器中)。 I also tried manager = null, but they all cause me the application to force close.我也试过 manager = null,但它们都导致我应用程序强制关闭。 Where am I going wrong?我哪里错了? Thank you.谢谢你。

The problem was that I didn't write super.onDestroy().问题是我没有写 super.onDestroy()。 Silly me...傻我...

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

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