android-interview-questions icon indicating copy to clipboard operation
android-interview-questions copied to clipboard

red food

Open hellosagar opened this issue 1 year ago • 4 comments

  • Internal workings: findByViewId, coroutines, dispatchers, before satartup
  • Retrofit, interceptors
  • flow vs livedata

hellosagar avatar May 22 '24 12:05 hellosagar

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 avatar May 23 '24 09:05 hellosagar

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 avatar May 23 '24 09:05 hellosagar

What happens on the app start:

image

Screenshot 2024-05-23 at 11 44 54 AM

hellosagar avatar May 23 '24 09:05 hellosagar

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.

hellosagar avatar May 23 '24 15:05 hellosagar