开发者

Android Canvas two activities - content drawn on second canvas

开发者 https://www.devze.com 2023-04-05 02:23 出处:网络
I don\'t know how this is possible, but a canvas from Activity A is appearing on top of my canvas in activity B.Both activities are always alive (they are in an activity group).How is it even possible

I don't know how this is possible, but a canvas from Activity A is appearing on top of my canvas in activity B. Both activities are always alive (they are in an activity group). How is it even possible that content from a canvas on one activity could be showing on top of my other activity?

I call this when i'm done with either activity A or B, but it obviously isn't working:

void clearPlayerCanvas()
{
    runOnUiThread(new Runnable(){
        public void run()
        {

            Canvas canvas = null;
            try
            {

                canvas = holder.lockCanvas();

                if (canvas == null)
                {
                    System.out.println("Cannot lock canvas, skipping MJpeg frame");
                    return;
                }


                canvas.drawColor(Color.BLACK);


            } 
            finally 
            {
                if (canvas != null)
                    holder.unlockCanvasAndPost(canvas);


            }
        }
        });
}

This code simply overwrites (its supposed to) the current canvas with black. In any case, i shouldn't even be seeing this black canvas in activ开发者_运维知识库ity b, but I am. I am also using SurfaceHolder.


You shouldn't have two Activities running at the same time (in fact, I don't think you can).

You didn't stop the thread drawing to your SurfaceView in ActivityA. Threads continue to run even when an Activity pauses, so I assume that was it.

0

精彩评论

暂无评论...
验证码 换一张
取 消