Android 动画导致“历史记录的活动空闲超时”启动时
我一直在寻找这个问题的答案,虽然我可以找到其他人在日志猫中看到相同的条目,但没有一个足迹似乎与我的相似。
基本上,我在活动启动时开始无限重复的动画。屏幕渲染正确,响应所有触摸输入,但我在 logcat 中收到以下条目:
08-17 16:03:25.910: WARN/ActivityManager(110): 启动超时已过期,放弃唤醒锁! 08-17 16:03:25.972: WARN/ActivityManager(110): HistoryRecord{4057ad58 com.companyname.dm/.ui.activities.home.HomeActivity} 的活动空闲超时
我读过的帖子指出这些条目确实只是警告指示主线程循环程序从未闲置,并且如果它是预期的操作模式,则不是问题。然而,除了小重复动画(每 3 秒重复一次的缩放/变换/Alpha 动画)填充消息队列这一事实似乎过多之外,我的主要问题是它阻止了创建自动化测试的能力。我们正在尝试使用 Robotium 实现测试,但由于空闲超时,测试永远不会开始。
不启动动画可以消除这个问题,但它更像是一种解决方法,而不是根本原因解决方案。我试图了解我是否没有正确实现动画,这是否确实只是预期的行为,或者是否有办法确保建立仪器/机器人的连接。
任何见解将不胜感激!谢谢。
I have been searching for an answer to this and while I can find others who have been seeing the same entries in the log cat none of the footprints seem to be similar to mine.
Basically I start an infinitely repeating animation as part of my activity start up. The screen is rendered properly, is responsive to all touch input but I get the following entries in my logcat:
08-17 16:03:25.910: WARN/ActivityManager(110): Launch timeout has expired, giving up wake lock!
08-17 16:03:25.972: WARN/ActivityManager(110): Activity idle timeout for HistoryRecord{4057ad58 com.companyname.dm/.ui.activities.home.HomeActivity}
I have read posts that state these entries are indeed just warnings to indicate the main thread looper has never become idle and not a problem if it is the intended mode of operation. However, besides that fact that it seems excessive that the small repeating animation (a scale/transform/alpha animation that repeats every 3 seconds) is filling the message queue, my main issue is that it is preventing the ability to create automated tests. We are trying to implement a test using robotium but the test will never start because of the idle timeout.
Not starting the animation will eliminate this problem, but is much more a workaround than a root cause solution. I am trying to understand if I am either not implementing my animations properly, if this is indeed just the expected behavior or if there is a way to ensure the connection the instrumentation/robotium will be established.
Any insight would be greatly appreciated! Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在新线程中启动动画,如果您在 onCreate 方法中执行太多操作,您将阻塞 Android 中的 UI 线程,并且如果您之前花费的时间超过 5 秒,则可能会导致 ANR(应用程序不响应)返回。通过在新线程中启动动画,onCreate 将返回,系统会很高兴。
Try starting your animation in a new thread, if you do too much stuff in the onCreate method you will block the UI-thread in Android, and it could possibly lead to an ANR (Application not responding) if you take longer than 5 seconds before returning. By starting your animation in a new thread the onCreate will return and the system will be happy.
重新绘制到屏幕的代码需要在不同的线程中启动,否则主 UI 线程将永远不会空闲,这会导致问题。
从另一个线程与 UI 交互时,您可能会遇到问题,为此您应该查看 AsyncTask 实际上是用来计算/绘制进度条的。警告数量如此之多很可能是因为警告是在 X 秒后的任何时间生成的,这仅受 Android 检查的限制。
The code which is repainting to the screen need to be started in a different thread, else the main UI thread will never become idle, which is causing the problem.
You may have issues when interacting with the UI from another thread, for this you should look into AsyncTask which is actually what is used to compute/draw progress bars. The obscene number of warnings is most likely because the warnings are generated any time after X seconds, which is only limited by Android's checks.