Is main thread the same as UI thread?

Android

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

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.

Solution 2 - Android

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.

Solution 3 - Android

Basically Main Thread is Ui Thread.
However sometimes they can be different treads!
It is possible for system apps with multiple views on different threads.
Also if you use support annotations note that both @MainThread and @UiThread are available at the same time.
Here with the first one you annotate methods associated with the App life cycle and with the second one methods that are in charge of view hierarchy.
https://developer.android.com/studio/write/annotations.html

Solution 4 - Android

The "main application thread" is sometimes called the "UI thread".

Solution 5 - Android

Every Activity has its own UI thread. As soon as the VM boots up, System Server is started by the Zygote. All other services like Activity Manager Service are started in new threads by the System Server.

Solution 6 - Android

Yes. main thread is UI thread.

See this tutorial for full details about background processing in android

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser256239View Question on Stackoverflow
Solution 1 - AndroidAndy ZhangView Answer on Stackoverflow
Solution 2 - AndroidKartihkraj DuraisamyView Answer on Stackoverflow
Solution 3 - AndroidLeonid UstenkoView Answer on Stackoverflow
Solution 4 - AndroidCommonsWareView Answer on Stackoverflow
Solution 5 - AndroidRajdeep DuaView Answer on Stackoverflow
Solution 6 - AndroidNguyen Minh BinhView Answer on Stackoverflow