Good programming practice for calling invalidate () inside onDraw ()?

  • Good programming practice for calling invalidate() inside onDraw() ?

As I understand it, calling invalidate() inside onDraw() is expensive and not required if there are no changes to the canvas.

  • Is invalidate() equivalent to the asynchronous version of onDraw() ?

In my understanding, they are equivalent. Correct me if I am wrong. Thanks.

+8
android ondraw
source share
1 answer

Only invalidate() is called if your data has been changed and needs to be redrawn. Usually you do not do this in onDraw() , because at this moment you are drawing the current data, not changing it. (There are some cases where you can do this, for example, to run animations, but usually I would recommend using a delayed message instead to control your own update time.)

+17
source share

All Articles