开发者

asyncTask update a static value which is used by OpenGL ES

开发者 https://www.devze.com 2023-04-03 13:39 出处:网络
I m writing an app containing an asyncTask which continuously (every seconds or so) adds a value to an ArrayList<Float> (declared static).

I m writing an app containing an asyncTask which continuously (every seconds or so) adds a value to an ArrayList<Float> (declared static).

The value is a measure in inches that I want to plot. In order to do that I have implemented a solution with OpenGL ES. And every time I add a new value my AsynTask calls the requestRender() method. Then the drawRenderer() take the ArrayList<Float> and draw lines with it.

At this 开发者_开发知识库point everything works perfectly fine.

I also want that the user can pinch-zoom and move the plot. So I have a TouchsurfaceView which also calls requestRender() when needed. Most of the time it works, but time to time I get an error because of concurrent requests for the ArrayList<Float> (almost sure of that).

Any ideas How can I solve this ? I see lock and synchronized stuff, but can t find how to properly use them for my case.

Thanks for reading me.


put all the updates to the static variable in a synchronized static method and use only that for making updates.

0

精彩评论

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