开发者

passing array by calling activity from a thread

I have two activities:

  1. "a" that spawns thread for generating a dynamic array of values inside public void run() function.

  2. "b", graphics activity that will help me draw rectangular pulses based on array values calculated in activity "a" (calculated in a's thread 开发者_如何转开发to be precise).

When I am in thread inside "a", how do I pass values of array to activity "b" and call activity as well.

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
}


You may want to check out the SpriteMethodTest sample application; it contains much Canvas vs OpenGL diagnostic code, but in essence does what you intend to do. The main point is that separation of physics and renderer is not done by creating two Activities, but by having the following architecture:

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)

Therefore, you don't need to pass objects between two activities; and in fact, one activity makes more sense, since both the physics and the rendering will be executed at the same time.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜