When you ask a View to draw itself, you have to draw the whole thing - it doesn't remember what you drew last time.
By creating a backing bitmap and drawing to that, you avoid the problem.
In the first code you uploaded, when you get pointer events you push points onto a path, but clear it on a pointer up (so when you draw after that point you get a blank canvas.)
In the second version of the code, you don't clear the contents of the path. So every point you have added remains in the path. Now when you change the colour the entire path gets drawn in the new colour.
The third version of the code is like the first version, except you draw to a bitmap. Now after a pen up the path is cleared, but the pixels you have drawn remain on the bitmap. When you change colour new paths are drawn in the new colour, but because you cleared the old points from the path you don't draw over the top of your old lines.