hellosagar / android-interview-questions

I'm contributing to help others!
MIT License
49 stars 15 forks source link

red food #35

Open hellosagar opened 4 months ago

hellosagar commented 4 months ago
hellosagar commented 4 months ago

Working of Coroutines: From a thread pool, a thread is used. and within that a corutine will be run, if another task is added to the same coroutine, that mean its in the same thread, run sequently. Once the both corutines running in the thread are done, thread will be sent back to the thread pool

Also, when we add suspend to a method, in java bytecode, it will essentially add a continousity param to the method. this continuity can stop, resume or throw exception for the running task in courtine

hellosagar commented 4 months ago

working of findViewById: for each xml tag, a there is a java class, which we get reference as view in the activity, and then we downcast to get the specific properties

hellosagar commented 4 months ago

What happens on the app start:

image

Screenshot 2024-05-23 at 11 44 54 AM
hellosagar commented 4 months ago

Dispatcher: Responsible for deciding which thread or threads will execute your coroutines.

Dispatcher.IO vs Dispatcher.Default:

Dispatchers.Default is specifically designed for CPU-intensive tasks because it provides a fixed-size thread pool that matches the number of available CPU cores. This design ensures optimal CPU utilization, minimizes context switching overhead, and offers predictable performance. In contrast, Dispatchers.IO is better suited for I/O-bound tasks due to its elastic thread pool, which can handle a high number of blocking operations efficiently but is not suitable for CPU-bound tasks due to the risk of thread contention and starvation.