1

I am using invalidate() in my onDraw to get a loading view but it is not starting the onDraw call.

public void onDraw(Component component, Canvas canvas) {
<function body>
invalidate()
}
zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
  • 2
    I don't know this particular API, but it's very common for similar systems to automatically consider everything valid after the draw callback returns, so invalidate calls inside have no effect. For example, IIRC WinAPI's WM_PAINT message works the same way. – Sebastian Redl Jul 30 '21 at 07:08
  • hi@yashrajgupta,could you pls post some of your code for us to locate this issue?And just to confirm, is the `addDrawTask` method added? – zhangxaochen Aug 03 '21 at 09:52

1 Answers1

0
  1. Make sure you are calling the addDrawTask method in your implementation
  2. Even after calling the addDrawTask method, if invalidate() is not called on UI thread, then the onDraw() might not be invoked on UI thread. Therefore, we can be sure of calling it on UI thread by implementing the following statement :
 context.getUITaskDispatcher().asyncDispatch(this::invalidate);

This personally worked for me when i was trying to call the onDraw() method continuously for displaying an animation.

Samuel
  • 36
  • 3