Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between MainThread, UiThread, WorkerThread, BinderThread in Android Annotation

As i read in the android annotations for thread document

We have four types of thread,

  • @MainThread
  • @UiThread
  • @WorkerThread
  • @BinderThread

What is differences?

like image 993
AliSh Avatar asked Aug 08 '15 10:08

AliSh


People also ask

What is Mainthread Android?

When an application is launched in Android, it creates the first thread of execution, known as the “main” thread. The main thread is responsible for dispatching events to the appropriate user interface widgets as well as communicating with components from the Android UI toolkit.

What is the difference between main thread and UI thread in 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.

What is the difference between service and thread in Android?

Service : is a component of android which performs long running operation in background, mostly with out having UI. Thread : is a O.S level feature that allow you to do some operation in the background.

How is main thread different from normal thread?

The "main" thread is being initialized there, and all calls to Activity lifecycle methods are being made from that exact thread. In Activity#attach() method (its source was shown above) the system initializes "ui" thread to "this" thread, which is also happens to be the "main" thread.


1 Answers

The differences is:

  • @MainThread, first Thread run when app started,
  • @UiThread, run from MainThread for UI works,
  • @WorkerThread, that run when programmer define a thread
  • @BinderThread,uses for something like query()/insert()/update()/delete() methods in ContentProvider.
like image 186
AliSh Avatar answered Sep 24 '22 23:09

AliSh