Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Handler class? [closed]

What is a Handler class in Android?

like image 373
EAGLE Avatar asked May 16 '13 19:05

EAGLE


People also ask

What does a handler class do?

Handlers classes are used to Handle the execution of triggers. If you are working on custom application development on force.com or customizing salesforce to do event-driven updates, you will end up writing quite a few triggers and in some cases more than one trigger on the same object.

What is a handler object in Java?

A Handler object takes log messages from a Logger and exports them. It might for example, write them to a console or write them to a file, or send them to a network logging service, or forward them to an OS log, or whatever. A Handler can be disabled by doing a setLevel(Level.

Which thread will process a message posted to a handler?

Android handles all the UI operations and input events from one single thread which is known as called the Main or UI thread. Android collects all events in this thread in a queue and processes this queue with an instance of the Looper class.


2 Answers

A handler is basically a message queue. You post a message to it, and it will eventually process it by calling its run method and passing the message to it. Since these run calls will always occur in the order of messages received on the same thread, it allows you to serialize events.

like image 83
Gabe Sechan Avatar answered Sep 20 '22 12:09

Gabe Sechan


As given in Handler documentation on android dev site, there are two main uses for a Handler:

  1. To schedule messages and runnables to be executed as some point in the future; and
  2. To enqueue an action to be performed on a different thread than your own.
like image 31
stinepike Avatar answered Sep 22 '22 12:09

stinepike