I am having problems redrawing the view in a painting app. When the touch ends, I call touch_up() to make the path, invalidate() to draw it, and storeView() to push the current view on the stack. However, the view is not redrawn at all (until the next touch, giving it a twitchy effect). If I delete the call to storeView() it does redraw right away.
I understand from here that the issue is invalidate() does not necessarily happen immediately and I think I need to create a new thread or handler to wait for it. Despite reading the dev pages, I don't fully understand how to implement that.
Is that really what I need to do? How can I make storeView() wait until the view has been redrawn? I've fought with this a while, an answer would make my day. Thanks!
Here's what I currently do.
Action_up:
case MotionEvent.ACTION_UP:
touch_up();
invalidate();
storeView();
break;
Touch_up:
private void touch_up() {
mPath.lineTo(mX, mY);
// commit the path to our offscreen
mCanvas.drawPath(mPath, mPaint);
// kill this so we don't double draw
mPath.reset();
}
storeView:
public void storeView(){
historyCount++;
if(historyCount > historySize) historyCount = 6; //We don't want more than 6
history.add(Bitmap.createBitmap(myView.getDrawingCache()),historyCount);
}