问题描述
我有两个活动:
产生用于在
public void run()
函数内部生成值的动态数组的线程的“ a”。图形活动“ b”将帮助我根据活动“ a”(准确地说是在a的线程中计算)中计算出的数组值绘制矩形脉冲。
当我在“ a”内部的线程中时,如何将数组的值传递给活动“ b”并调用活动。
activity a
{
thread - array calculation,
call activity b,
pass array values,
call another activity
}
activity b
{
store array values from activity a,
draw rectangles based on array values
}
1楼
您可能需要签出 ; 它包含许多Canvas vs OpenGL诊断代码,但实际上可以完成您打算做的事情。 要点是,物理和渲染器的分离不是通过创建两个“活动”来完成的,而是通过具有以下架构来完成的:
Activity (i.e. InGameActivity, which loads the game objects, Physics and Renderer)
-> SurfaceView (which maintains a thread or two for the Physics and Renderer)
-> Physics (created by the Activity, passed through a method)
-> Renderer (created by the Activity, passed through a method)
因此,您不需要在两个活动之间传递对象。 实际上,一项活动更有意义,因为物理和渲染将同时执行。