Build: Thread Switch Demo
This screen shows how to switch threads using withContext in Kotlin coroutines. It fetches a message on a background thread and updates the UI on the main thread.
Target UI
------------------------- | Thread Switch Demo | |-----------------------| | | | Message: | | [Loading...] | | | | [Fetch Message Button] | -------------------------
Add a Button labeled 'Fetch Message Button'.
When tapped, start a coroutine that switches to a background thread to simulate fetching data.
Use withContext(Dispatchers.IO) to switch to background thread.
After fetching, switch back to the main thread to update the TextView with the fetched message.
Show 'Loading...' text while fetching.