You mustn't take the reference to the Canvas passed, as it is only valid during the onDraw(Canvas)
method call.
I recommend reading http://developer.android.com/guide/topics/graphics/2d-graphics.html#draw-with-canvas thoroughly, the possible ways are explained there quite well:
- To the Canvas provided to the
onDraw(Canvas)
method, during this method call. This is done in the UI thread, so nothing complicated should be attempted here - To a Canvas you created yourself. This could be useful for preparing a bitmap in another thread and then drawing the bitmap to the Canvas given to
onDraw(Canvas)
method - Using a SurfaceView, and obtaining a Canvas object from it with
lockCanvas()
method.