0

I developed several codes using HandlerThread, but so far, it is to some extent difficult to grasp the meaning of the run() method that exists in the Handlerthread class when extended.

HandlerThread class, when extended, some abstract methods are to be overridden. One of them is:

run()

Would you please clarify the usage of it in the HandlerThread class?

Ryan M
  • 18,333
  • 31
  • 67
  • 74
Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • I'm not an android developer, and I can't answer, but is it possible that what you _really_ are asking here is, "what is the purpose of the `HandlerThread` class?" I looked at its documentation, and I couldn't figure out what it's for (i.e., I couldn't see who calls it, or when, or why) but it sure looks as of the entire point of that class is to call that `run()` method at the right time (or probably, times). – Solomon Slow Apr 24 '20 at 17:26

1 Answers1

2

HandlerThread is a subclass of Thread, and Thread has a run() method.

HandlerThread overrides that in order to do its work, because that's how Threads are implemented. Unfortunately, it doesn't replace the JavaDoc comment with its own, so the documentation is copied from the Thread class, which results in confusing documentation here.

As far as how you should use it: you shouldn't. It's an implementation detail that is, unfortunately, public. You shouldn't override it or call it. Just get the Looper and use that to post things to the HanderThread.

Ryan M
  • 18,333
  • 31
  • 67
  • 74