详细的Android活动生命周期(onAttachedToWindow()) [英] Detailed android activity lifecycle (onAttachedToWindow())

查看:896
本文介绍了详细的Android活动生命周期(onAttachedToWindow())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对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.

我的需要来自于从开始新的活动( Theme.Dialog 样式) onAttachedToWindow()如果与从onCreate()启动它相比较,可以大大提高响应时间。我不知道这个 onAttachedToWindow()如何适应整个android活动生命周期。官方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.

推荐答案

我猜测为什么感觉更敏感,离开我的头顶:我认为如果从活动A的onCreate()启动活动B,活动A在活动B开始之前未绘制,这可能再花一两秒钟(使应用程序感觉回复更少),如果在活动A的onAttachedToWindow()中启动活动B,则在B被启动之前启动和呈现A,因此用户不必再等待一秒在看到对他们的行动的反应之前,有一个空白屏幕或前A活动。

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.

这篇关于详细的Android活动生命周期(onAttachedToWindow())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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