屏幕锁定时调用了Android活动onDestroy() [英] Android activity onDestroy() called on screen lock

查看:64
本文介绍了屏幕锁定时调用了Android活动onDestroy()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

onDestroy 函数.我知道这不应该发生,因为控制流应该是onPause()-> onStop().在锁定屏幕上,控制流程如下: onPause()-> onStop()-> onDestroy().我已经在我的android清单中给出了android:configChanges="orientation|keyboardHidden",这是对类似问题的答案所建议的,但是没有用.从onStop()检查时,isFinishing()函数返回false.

onDestroy function in my activity class gets called when screen sleeps or if screen is locked. I know this should not happen as the flow of control is supposed to be onPause()->onStop(). On locking screen the flow of control is like this: onPause()->onStop()->onDestroy(). I have given android:configChanges="orientation|keyboardHidden" in my android manifest as suggested by answers to similar questions but that did not work. isFinishing() function returns false when checked from onStop().

任何人都可以帮我解决这个问题.

Can anyone please help me solve this issue.

推荐答案

我在这里遇到了同样的问题:

I had the same problem here:

活动生命周期X电源按钮X锁定屏幕

解决方案是像您一样添加configChanges,但是您缺少 screenSize 类型:

The solution was to add the configChanges like you did, but you are missing the screenSize type:

android:configChanges="orientation|keyboardHidden|screenSize"

这篇关于屏幕锁定时调用了Android活动onDestroy()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆