I used to do my drawing in an ImageView in the onDraw method.
However, I’ve learnt that’s better to draw the canvas outside of the onDraw and just update the canvas in onDraw.
I know this is clearly wrong (because it’s not working) but how would I accomplish what I’m trying to do:
@Override
public void onDraw(Canvas c) {
c = this.newCanvas;
super.onDraw(c);
}
make that thread then in your activity do something like this
then in a GameViewClass do something like this
The important things here is that the thread is manually auto calling the onDraw() method repeatedly, and that you are locking a canvas, drawing on it, and then posting it. If you dont need a super fast refresh rate then you might be better off doing something like this:
I just dont know if that last bit there will work, never tested it.
also if you want to do your drawing outside the on draw method, you could run your updating (drawing on your canvas) in a thread, and every time the onDraw method is called have it check to see if the Canvas is ready for it to post. for example have your thread have a boolean that once the canvas gets pulled it is set to false, so the thread will draw you a new one, but once it is done drawing set the boolean to true. in the ondraw method check to see if the boolean is true and if it is pull the canvas.