gpt4 book ai didi

android - onResume 在手机屏幕锁定时被一遍又一遍地调用

转载 作者:IT老高 更新时间:2023-10-28 23:33:08 27 4
gpt4 key购买 nike

看来,如果在手机屏幕锁定时某个 Activity 处于前台,则广播事件和/或唤醒锁将导致该 Activity 的 onResume 被调用,无论它们是否适用于您的应用。即使您不以任何方式与手机互动,也会发生这种情况。不要解锁,不要触摸,不要做任何事情,你的 onResume 会被一遍遍地调用,没有对应的 onPause。

我们注意到这一点是因为我们在 onResume 上记录了一个跟踪事件,并且我们注意到一些设备收到了大量这些 onResume 事件。我们能够重现并注意到,每当任何应用似乎接收到 Intent 时都会发生这种情况(例如 SugarSync、Google Voice 或我们自己应用中的被动位置监听器)。

我们在运行 ICS 的 Galaxy Nexus 和 Galaxy S3 上注意到了这一点。有趣的是,我们无法在 Jelly Bean 上重现该问题。

有人对这里可能发生的事情有任何指示吗?

最佳答案

我在几部运行 Gingerbread 和 ICS 的手机上观察到了相同的行为。你的描述和我看到的相符。出于某种原因,即使屏幕仍处于锁定状态, Activity 也会触发 onResume。也许它恢复对某些操作系统级别的事件?

android 文档的最佳方向似乎来自 onResume 中的这一段。定义:

Keep in mind that onResume is not the best indicator that your activity is visible to the user; a system window such as the keyguard may be in front. Use onWindowFocusChanged(boolean) to know for certain that your activity is visible to the user (for example, to resume a game).

在开发 Activity 时,请记住 onResume 可能会被快速连续调用多次,而无需任何直接的用户交互。因此,基本上,不要在 onResume 中放置任何只能运行一次或旨在触发用户立即响应的代码。您必须自己决定 onResume 或 onWindowFocusChanged 是否更适合您想要做的事情。

关于android - onResume 在手机屏幕锁定时被一遍又一遍地调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11731285/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com