当前位置: 代码迷 >> Android >> 通过从线程调用活动来传递数组
  详细解决方案

通过从线程调用活动来传递数组

热度:25   发布时间:2023-08-04 09:45:04.0

我有两个活动:

  1. 产生用于在public void run()函数内部生成值的动态数组的线程的“ a”。

  2. 图形活动“ 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
}

您可能需要签出 ; 它包含许多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)

因此,您不需要在两个活动之间传递对象。 实际上,一项活动更有意义,因为物理和渲染将同时执行。

  相关解决方案