android - onAttachedToWindow 和 onStart 之间的确切区别是什么

标签 android android-activity lifecycle oncreate

我有时看到人们使用 Activity.onAttachedToWindow 方法,但就我个人而言,我从未使用过它。在阅读它的文档时,我觉得它与 onStart() 几乎相同。

我假设的一件事是: onAttachedToWindowonCreate() 之前被调用 onStop 之后被调用。

我的假设是否正确? 两者的代表是什么?您什么时候使用哪个?

最佳答案

onAttachedToWindow :

This is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before onDraw(android.graphics.Canvas), however it may be called any time before the first onDraw -- including before or after onMeasure(int, int).

Activity Lifecycle is explained here .

我发现“starting new activity (Theme.Dialog styled) from onAttachedToWindow() greatly improves response time if comparing to starting it from onCreate()

关于android - onAttachedToWindow 和 onStart 之间的确切区别是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8700406/

相关文章:

version-control - 生命周期工具套件

javascript - 如何从 Nest.js 中的服务触发应用程序关闭?

java - Struts2拦截器参数及其生命周期

java - 启动 3d 派对应用程序后崩溃,该应用程序崩溃后

安卓应用搜索按钮

java - 未连接充电器时 Android 速度变慢?

android - 从其他 Activity 中引用静态 ServiceConnection 是否正确?

android - 阻止 Unity Android 应用程序中的屏幕捕获

android - 单击应用程序的启动图标时会发生什么?

android - 无法捕获工具栏主页按钮单击事件