I am writing my first android app. So am still in the learning phase.
Its very simple, I draw a graphic in the onDraw() in the center of the screen and with the onTouch event will have to move the graphic to the point where the user touched. For this the onTouch event will start a thread and update the graphic. The problem is the canvas.draw() is working when called from onDraw() but does not update the canvas/screen when called from within the thread.
My function drawSplash( Canvas c, Location l );
I call the same function in both the onDraw() and the thread.
The only difference in the code I can see is I am storing the Canvas object passed in to me in the onDraw() function in a variable in my class so that I can use it in the thread again. This somehow feels wrong. If so, what is the correct way to do this? Can I get the Canvas object anytime I want? How do I do that?
- P
You have to .invalidate() your view with has the onDraw method overrited. Each time it’s called it should draw the Graphics on the right position.
And you should call the .invalidate() method inside the Main Thread.