Android Canvas 两个活动 - 在第二个画布上绘制内容

发布于 2024-12-04 11:47:43 字数 871 浏览 0 评论 0原文

我不知道这是怎么可能的,但是活动 A 中的画布出现在活动 B 中的画布顶部。这两个活动始终处于活动状态(它们位于活动组中)。一项活动的画布内容怎么可能显示在我的另一项活动之上?

当我完成活动 A 或 B 时,我会调用此方法,但它显然不起作用:

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);


            }
        }
        });
}

此代码只是用黑色覆盖(应该是)当前画布。无论如何,我什至不应该在活动 b 中看到这个黑色画布,但我看到了。我也在使用 SurfaceHolder。

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 activity b, but I am. I am also using SurfaceHolder.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无风消散 2024-12-11 11:47:43

您不应该同时运行两个活动(事实上,我认为您不能)。

您没有停止在 ActivityA 中绘制 SurfaceView 的线程。即使 Activity 暂停,线程也会继续运行,所以我认为就是这样。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文