There are a lot of similar questions and therefore this may seem like a duplicate but please read first.
I have gone through all of the following questions and it didn't work for me
- onDraw() is not called in custom View
- invalidate not redrawing view on api 25
- Android Custom Layout - onDraw() never gets called
- view.invalidate() not working to redraw imageview
- Why onDraw is not called after invalidate()?
- Android View Canvas onDraw not performed
Let me clarify further
- I am extending View class not any ViewGroup like LinearLayout etc
- when I call
invalidate()
fromonTouchEvent
it runs fine - when I call
invalidate()
from another function of the same class (undo()
)invalidate()
doesn't work - I also tried calling
postInvalidate()
and also called invalidate usingpostDelayed(new Runnable ... invalidate()
nothing seems to work. - after touching undo button when I touch the view it draws the expected result immediately.
Any suggestion on what could be the issue?
code looks something like below
public boolean undo() {
if (undoStack.isEmpty()) return false;
redoStack.push(undoStack.pop());
if (redoStack.size() >= MAX_STACK_SIZE) redoStack.removeElementAt(0);
// invalidate();
postInvalidate();
return true;
}
here undoStack holds the previous bitmaps that were drawn
I can say that undo and onDraw are working fine as I get the expected results when I touch the view after clicking on undo button. Also I am calling this function from the main Thread and not background thread or async task.
Any suggestions please. Thanks in advance.