Understanding the main thread
summary
Explains how the main thread runs an infinite Looper/MessageQueue loop and how a Handler.post enqueues runnables, then demonstrates with lifecycle logs that posts from onCreate/onStart/onResume often execute in the same runnable, that posts from onStop can run after onDestroy, and that view width/height are zero until layout finishes so ViewTreeObserver.OnGlobalLayoutListener is the right tool (not magic postDelayed). Shows LiveData.setValue/postValue differences: setValue runs immediately on main thread, postValue defers and can drop frequent updates.
AI-written summary · about
chapters (15)
- 0:00Introduction and speaker
- 0:52What is the main thread
- 2:16Why single main thread
- 3:00Messages and message queue
- 4:26How looper works
- 6:35Using handler to post
- 9:30Competing tasks on main thread
- 10:39Life cycle callbacks order
- 12:33Measuring view dimensions
- 14:02Global layout listener
- 14:44LiveData behavior
- 17:20LiveData in onResume
- 18:48Post vs set on LiveData
- 20:32Key takeaways summary
- 22:12Q&A
related talks
29mLooper.loop() - Understanding Android's Message Queue
30mExtra! Extra! Thread all about it!
28mInside Android asynchronous processing: Understanding the Event Loop
27mAndroid Components under the hood
23mLifecycle, LiveData, Viewmodels - The inner wiring
37mAsync Task, Threads, Pools and Executors
57mHow Espresso Works
33mUntangle your App: Efficient Threading in Android
