Skip to main content
UI thread and backgound thread..

UI thread in Android

  • When an app icon is clicked to launch it, system starts a new process and runs the main activity on a new thread if the app is not already started. All the subsequent user interactions with the app and components handle the interactions run on the the same thread. This thread is called main thread.
  • If an app is already running on a thread and a component is requested, the component will run on the existing thread for the app.
  • Background or worker thread can be created within the app to run long running tasks.
  • Main thread is also called UI thread as all UI components run on the main thread. But in system apps, UI thread can be different from main thread if views run on different threads.

Comments

Popular posts from this blog

Looper What is looper? Looper is a class which is used to execute the Messages(Runnables) in a queue. Normal threads have no such queue, e.g. simple thread does not have any queue. It executes once and after method execution finishes, the thread will not run another Message(Runnable). Where we can use Looper class? If someone wants to execute multiple messages(Runnables) then he should use the Looper class which is responsible for creating a queue in the thread. For example, while writing an application that downloads files from the internet, we can use Looper class to put files to be downloaded in the queue. How it works? There is prepare() method to prepare the Looper. Then you can use loop() method to create a message loop in the current thread and now your Looper is ready to execute the requests in the queue until you quit the loop.