@Override
 public void onSurfaceDestroyed(SurfaceHolder holder) {
   super.onSurfaceDestroyed(holder);
   boolean retry = true;
   painting.stopPainting();
   while (retry) {
     try {
       painting.join();
       retry = false;
     } catch (InterruptedException e) {
     }
   }
 }
    @Override
    public void onDestroy() {
      super.onDestroy();

      painting.stopPainting();
    }