Android Canvas 两个活动 - 在第二个画布上绘制内容
我不知道这是怎么可能的,但是活动 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该同时运行两个活动(事实上,我认为您不能)。
您没有停止在
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
inActivityA
. Threads continue to run even when anActivity
pauses, so I assume that was it.