Daniel Kobe
Daniel Kobe

Reputation: 9825

Using a callback vs using Handler in Android?

Im learning from Android's BluetoothChat sample app and noticed that they are using a Handler to send updates to the UI as seen here . I was wondering why they wouldn't prefer to use a callback/listener to send updates to UI?

Upvotes: 1

Views: 1574

Answers (2)

stackvoid
stackvoid

Reputation: 127

For a Guess. Handler is a perfect async solution. just post message to the MessageQueue,Handler(UI Thread) will take message from it. It can reduce your module's complexity.

CallBacks is another solution,but complex according Handler to update UI.

Upvotes: 1

Tomislav Novoselec
Tomislav Novoselec

Reputation: 4620

My guess is because Handler posts messages on the Thread it was created on. If you were using callbacks, you would have to take care of calling runOnUiThread(Runnable) in order to perform any kind of UI changes.

Upvotes: 3

Related Questions