Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between android.os.Handler and java.util.logging.Handler?

Question pretty much sums it. I mistakenly import the java.util.logging and don't get the desired functionality . Now i solve my problem but i want to know why android has created two Handler . We can mistakenly import the wrong one. Same as it did with Fragment and Support Fragment.

like image 513
Zar E Ahmer Avatar asked Dec 20 '22 12:12

Zar E Ahmer


2 Answers

From the Android documentation:

android.os.Handler:

A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue. Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it -- from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue.

From the Oracle documentation:

java.util.logging.Handler

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.OFF) and can be re-enabled by doing a setLevel with an appropriate level.Handler classes typically use LogManager properties to set default values for the Handler's Filter, Formatter, and Level

like image 143
M D Avatar answered Apr 07 '23 06:04

M D


java.util.logging.Handler comes from vanilla Java. It is a superclass to various types of logging endpoint (socket, file ...)

android.os.Handler is a class created by the android development team to handle messages.

There are other examples:

  • Apache DateUtils and Android DateUtils
  • java.lang.Integer and android.R.integer

...

As long as classes are in different packages, it is allowed for them to have the same name. (And it is inevitable, too, as people are bound to use the same name to refer to vaguely similar things)

like image 24
njzk2 Avatar answered Apr 07 '23 06:04

njzk2