user2476398
user2476398

Reputation:

Looper/Handler vs. Executor

Why use Looper/Handler when I could use an Executor method(s)?

The Looper/Handler duo seems rather clunky and doesn't seem to do a great deal beyond allowing the queuing of runnables and seemingly has less flexibility.

What was the looper design rationale?

Thanks.

Upvotes: 2

Views: 2134

Answers (1)

Patrick
Patrick

Reputation: 35234

A looper by itself does not have many advantages over an executor. It is how Android manages worker. But you are able to get the main thread of your app with Looper.getMainLooper(), this can have the following advantages:

  • You can change the ui from the MainLooper, (only do if not a compute intense background task, since you would freeze the UI)
  • Execute Runnables "in-sync" with the all the other native tasks. Meaning you post your Runnable in the same queue as android does
  • No need to create a thread yourself. You can use the already running Looper.

Upvotes: 2

Related Questions