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.
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.
The onSaveInstanceState() method allows you to add key/value pairs to the outState of the app. Then the onRestoreInstanceState() method will allow you to retrieve the value and set it back to the variable from which it was originally collected.
An Android activity goes through six major lifecycle stages or callbacks. These are: onCreate() , onStart() , onResume() , onPause() , onStop() , and onDestroy() .
onCreate() is called when the when the activity is first created. onStart() is called when the activity is becoming visible to the user.
onCreate() method calls the setContentView() method to set the view corresponding to the activity. By default in any android application, setContentView point to activity_main. xml file, which is the layout file corresponding to MainActivity.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With