Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is main thread the same as UI thread?

Tags:

android

The Android doc says "Like activities and the other components, services run in the main thread of the application process."

Is the main thread here the same thing as UI thread?

like image 764
user256239 Avatar asked Jul 16 '10 01:07

user256239


People also ask

What is the main UI thread?

Main Thread: The default, primary thread created anytime an Android application is launched. Also known as a UI thread, it is in charge of handling all user interface and activities, unless otherwise specified. Runnable is an interface meant to handle sharing code between threads. It contains only one method: run() .

Which are the two main types of thread in Android?

There're 3 types of thread: Main thread, UI thread and Worker thread. Main thread: when an application is launched, the system creates a thread of execution for the application, called main.

What is main thread in Android?

When an application is launched in Android, it creates the primary thread of execution, referred to as the “main” thread. Most thread is liable for dispatching events to the acceptable interface widgets also as communicating with components from the Android UI toolkit.

What is difference between worker thread and main thread?

People use the word "worker" when they mean a thread that does not own or interact with UI. Threads that do handle UI are called "UI" threads. Usually, your main (primary) thread will be the thread that owns and manages UI. And then you start one or more worker threads that do specific tasks.


2 Answers

Looks like it. Quoted from http://android-developers.blogspot.com/2009/05/painless-threading.html: "When an application is launched, the system creates a thread called "main" for the application. The main thread, also called the UI thread...", Official API document.

like image 67
Andy Zhang Avatar answered Sep 24 '22 01:09

Andy Zhang


UI Thread and Main Thread are same only in Android.

The Main thread, that is responsible for handling the UI events like Draw, Listen and receive the UI events.

Ans also it is responsible for interact with running components of the UI toolkit for the corresponding application that belongs to.

When an User event occurs in the application, the Main thread *

need to add the event in the queue -> intimate about the event to appropriate View -> change the state of the view -> redraw the view according to the state changes -> waiting for the response for the particular event action -> after intimated and event action completed need to delete the event in the queue.

*

The above every actions are handled by the Main thread (Not only the above operation, it is a one of the operation handled by the UI Thread), So if our application fails to respond the event about 5 seconds android will shows the error "not responding".

So only it is widely suggested to do the light processes in the UI thread.

Hope this answer is somewhat detail and helpful to the new android bees like me. I just shared what i learned about UI Thread. If i went wrong in anywhere please don't hesitate to recorrect me.

like image 21
Kartihkraj Duraisamy Avatar answered Sep 22 '22 01:09

Kartihkraj Duraisamy