Handler as a method parameter

From dispatchGesture doc,

callback AccessibilityService.GestureResultCallback: The object to
call back when the status of the gesture is known. If null, no status
is reported.

handler Handler: The handler on which to call back the
callback object. If null, the object is called back on the service’s
main thread.

That basically means, if you don’t provide a Handler then the given callback will run on main thread.

Running expensive UI updater task in main thread in general is always discouraged. So, when you’re passing a handler as method param, most of the time it is there to lighten the UI thread up by taking off some of the heavy duty tasks, process it in another thread(handler, in this case) and post the result when its done.

Leave a Comment