Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the exact difference between onAttachedToWindow and onStart

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?

like image 627
poitroae Avatar asked Jan 02 '12 11:01

poitroae


People also ask

What is the difference between onCreate and onStart activity?

onCreate() is called when the when the activity is first created. onStart() is called when the activity is becoming visible to the user.

What is the difference between onStop and onPause?

If screen times out on your activity, then onPause is called. After sometime if you will not open the screen then onStop will be called.

What is called after onRestart?

onRestart() is called after onStop() when the current activity is being re-displayed to the user.


1 Answers

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()"

like image 67
Yaqub Ahmad Avatar answered Nov 10 '22 00:11

Yaqub Ahmad