What is the exact difference between onAttachedToWindow and onStart
Asked Answered
K

1

10

I sometimes see people using the Activity.onAttachedToWindow method but personally, I did never use it. When reading it's documentation it appears to me as it would be almost the same as onStart().

One thing I assume is: onAttachedToWindow is invoked before onCreate() onStop is invoked after.

Am I right with this assumption? What are the behalfs of both and when do you use which?

Kosher answered 2/1, 2012 at 11:45 Comment(1)
for onStart()/onStop() see this:https://mcmap.net/q/80309/-android-activity-life-cycle-what-are-all-these-methods-forChelicera
C
16

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.

I found that "starting new activity (Theme.Dialog styled) from onAttachedToWindow() greatly improves response time if comparing to starting it from onCreate()"

Chelicera answered 2/1, 2012 at 12:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.