Reputation: 6544
I am developing an application that draws map.
Currently my logic looks like this:
1) I have an activity with a collection of layers (tiles, lines, squares etc...).
2) In the activity in showing a view that holds canvas.
3) Then in this view I call "RenderAll". What happens is that I go through all layers and call a render procedure on each one of them. I send canvas to my renderer and stuff gets painted in the canvas. Once done the onDraw gets called on my view and the image is complete and drawn in the view.
What I want is that each one of my layers draws separately. Meaning, I have to draw in different threads. So that when my map is moved, first the tiles are drawn, then the lines and so on. Also i need to cancel the task by moving my map.
Can some one please point me to a good tutorial how to do this? I am new in multi-threading...
Thank you.
Upvotes: 0
Views: 1256
Reputation: 115388
First, read this: http://download.oracle.com/javase/tutorial/essential/concurrency/
Then re-think your design. Do you really want to move street names and then the streets? Remember: it may take time, so for several seconds user will see "wrong" picture. And more: how many layers do you have? If number of layers may grow (for example custom titles, shop names etc) the number of threads in your design will grow too that does not seem a good idea.
Why not to have one drawing thread that draws all layers sequentially? It will probably work even faster than multithreaded solution and definitely easier to implement.
Upvotes: 2