Search code examples
javaandroidsleepthread-sleep

android - Sleep() and then draw


I want to sleep and then draw in onDraw:

protected void onDraw(Canvas canvas) {
    if (_rectPath) {
        canvas.drawPath(mRectPath, mFillPaint);
        // SLEEP HERE for 5 seconds
        canvas.drawPath(mRectPath, mNPaint);
    }
    canvas.drawPath(mPath, mPaint);
}

How would I implement sleeping for 5 sec? Basically I want it to wait 5 sec and then draw the next path, mNPaint.

Thanks!


Solution

  • You could use this method. Initialize Handler out side the ondraw method

    Handler handler = new Handler();
    And inside onDraw method
    
    
        handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        //Draw the previous paths.
                        // Adjust the paths here and draw it
                        invalidate();
                    }
                }, 5 * 1000);