difference between post(Runnable) and sendMessage(Message) in Handler
Asked Answered
R

1

6

I just want to know what is the exact difference between using sendMessage (Message msg) and post (Runnable r).

Since both these methods are going to run in Main UI Thread even if we have Seperate Runnable.

Rafaello answered 29/1, 2017 at 4:58 Comment(1)
Duplicate ? #11208557Selection
R
7

Behind the scenes they actually call the same code. SO it isn't a big concern. SendMessage may be slightly more efficient (fewer objects used because the post will create a Message object), but by so little as to not matter at all. Using sendMessage you can add a data object as well as a runnable, but you can do that with a Runnable if you aren't using an anonymous one and pass it in via constructor.

So the long and short of it is there isn't much of one. Use whichever is more convenient (which tends to be post).

Raleighraley answered 29/1, 2017 at 5:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.