Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good programming practice to call invalidate() inside onDraw()?

Tags:

android

ondraw

  1. Is it a good programming practice to call invalidate() inside onDraw()?

As per my understanding, calling invalidate() inside onDraw() is expensive and is not required if there is no change to the canvas.

  1. Is invalidate() equivalent to an asynchronous version of onDraw()?

As per my understanding, they are equivalent. Correct me if I am wrong. Thank you.

like image 501
hsbgowd Avatar asked Feb 15 '11 03:02

hsbgowd


1 Answers

Only call invalidate() if your data has changed and needs to be redrawn. You generally don't do this in onDraw(), because at that point you are drawing your current data, not changing it. (There are some cases where you may want to do this, such as for running animations, but generally I would recommend instead using a delayed message to control your own timing of the updates.)

like image 99
hackbod Avatar answered Oct 28 '22 01:10

hackbod