详细机器人的活动周期(onAttachedToWindow())机器人、周期、详细、onAttachedToWindow

2023-09-12 05:00:01 作者:无视沵的存在

我感兴趣的是Android的活动周期,我想获得更详细的说明/文件/参照比广泛使用的基本(onCreate-> onStart-> onResume)的 之一。

I'm interested in android activity lifecycle and I would like to get more detailed description/documentation/reference than widely available basic (onCreate->onStart->onResume) one.

我需要来自从 onAttachedToWindow认识到,开始新的活动( Theme.Dialog 风格)()大大提高如果对比,从开始的onCreate它的响应时间()。我不知道这篇 onAttachedToWindow()融入整个机器人的活动周期。官方的API参考描述的 的不会有很大的帮助。当窗口已被贴在窗口管理器叫做

My need comes from realizing that starting new activity (Theme.Dialog styled) from onAttachedToWindow() greatly improves response time if comparing to starting it from onCreate(). I wonder how this onAttachedToWindow() fits into whole android activity lifecycle. Official API ref description "Called when the window has been attached to the window manager" doesn't help a lot.

推荐答案

我的猜测,为什么,感觉更敏感,从我的头顶:我认为,如果从活动开始活动B A的onCreate(),活动一活动B开始之前,这可能需要另外两秒钟(使应用程序感觉不那么敏感),在那里,如果你开始在活动A的onAttachedToWindow()活动B没有绘制,A开始,并呈现前B被拉开序幕,所以的用户没有看到反应其作用之前坐用空白屏幕或preA的活性的第二

My guess for why that feels more responsive, off the top of my head: I think that if you start Activity B from activity A's onCreate(), Activity A isn't drawn before activity B starts, which may take another second or two (making the app feel less responsive), where if you start activity B in Activity A's onAttachedToWindow(), A is started and rendered before B is kicked off, so the user doesn't have to sit for a second with a blank screen or the pre-A activity before seeing a reaction to their action.