开发者

How to correctly dispose a SensorManager

开发者 https://www.devze.com 2023-03-02 10:20 出处:网络
Hey, I am using a SensorManager in my Android application. 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开

Hey, I am using a SensorManager in my Android application. 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开发者_JAVA百科. 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...)). I also tried manager = null, but they all cause me the application to force close. Where am I going wrong? Thank you.


The problem was that I didn't write super.onDestroy(). Silly me...

0

精彩评论

暂无评论...
验证码 换一张
取 消