Reputation: 3946
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
Reputation: 4389
Easier way - call postInvalidate method of view. This can be called on non-ui thread.
Upvotes: 2
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