Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use HandlerThread in Android

In android , Handler can be used to post / handle message, if I don't use a HandlerThread (pass its Looper to Handler), does that mean in this case Handler use MainThread (UI Thread) 's Looper ?

What result will get if Handler uses MainThread's Looper ? May cause mainThread blocked ?

like image 526
Daniel Avatar asked May 23 '12 03:05

Daniel


1 Answers

You would use HandlerThread in case that you want to perform background tasks one at a time and you want that those tasks will run at the order of execution.

For example if you want to make several network background operations one by one.

Yes, the HandlerThread has it's own looper and handlers could be created and post it, (so it would not block the main thread).

like image 87
oznus Avatar answered Oct 14 '22 19:10

oznus