'Delay before next line on code on android SurfaceView kotlin

Hello how can I delay the next line of code after drawing because the sleep() doesn't seem to draw the bitmap with canvas take a look at this code I read somewhere that you need to use synchronize() but I'm a beginner and don't know much

 if (position == mGameThread!!.targetPosition[x]) {
            tuney = BitmapFactory.decodeResource(resources, R.drawable.tuney_basic_finish)
            canvas.drawBitmap(
                targetPositionAnim,
                mUtils!!.convertDpToPixel(338.13.toFloat(), context),
                mUtils!!.convertDpToPixel(
                    1011.67.toFloat() + mGameThread!!.targetPosition[x],
                    context
                ),
                null
            )

            sleep(1000)
            if (isTuneyClicked) {
                for (Frame in 1..mBitmapAnim!!.maxTuneyTspBlueFrame) {
                    holder.setFormat(PixelFormat.TRANSLUCENT)
                    val tuneyClicked =
                        BitmapFactory.decodeResource(
                            resources,
                            mBitmapAnim!!.tuneyTapBlue(this, Frame)
                        )
                    canvas.drawBitmap(
                        tuneyClicked,
                        mUtils!!.convertDpToPixel(326.67.toFloat(), context),
                        mUtils!!.convertDpToPixel(
                            1004.33.toFloat() + mGameThread!!.targetPosition[x],
                            context
                        ),
                        null
                    )
                }
            }
            else {
            canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR)
            canvas.drawBitmap(
                tuneyDead,
                mUtils!!.convertDpToPixel(326.67.toFloat(), context),
                mUtils!!.convertDpToPixel(1004.33.toFloat() + mGameThread!!.targetPosition[x], context),
                null
            )
        }
            position = 1f
            x++
        }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source