Matthew
Matthew

Reputation: 3946

Best way to update a custom view in Android RunOnUiThread or Handler.post

I am writing a custom view that animates. Would it be better for the View to get access to it's parent Activity through casting the getContext() method to the Activity and then calling Activity.runOnUiThread or would it be better to simply use a handler and post View.invalidate messages?

Upvotes: 1

Views: 769

Answers (2)

Sameer
Sameer

Reputation: 4389

Easier way - call postInvalidate method of view. This can be called on non-ui thread.

Upvotes: 2

speakingcode
speakingcode

Reputation: 1506

Either works. IIRC runOnUiThread() will post anyway, and the runnable will get picked up by the system looper later. So whatever is easier for you. runOnUiThread sounds easier/cleaner in this case, IMO.

Upvotes: 0

Related Questions