title: what is best alternative of C++ Sleep() in java and android?
body: <p>I am basically a  C++ developer, but   have  moved   to Android recently.
  My question is what is the the best alternative of  C++(Windows) Sleep() function  in java? I just need a simple delay in execution of program in android (java) and  then resume it for each iteration of for loop. But When  I use Thread.sleep() in java  ,it cause some kind of hang to the android system and does not work as  expected.
   Hope you understand  my question and requirement. Please suggest a better way to get C++ Sleep() functionality in java.</p>
  
  <pre><code> protected void onDraw(Canvas canvas) {
              super.onDraw(canvas);
              Paint paint = new Paint();
              paint.setColor(Color.BLACK);
              paint.setStrokeWidth(5);
              paint.setStyle(Paint.Style.STROKE);
              Path path = new Path();
              path.moveTo(myPath[0].x, myPath[0].y);
              for (int i = 1; i &lt; myPath.length; i++) {
                  path.lineTo(myPath[i].x, myPath[i].y);               
                  canvas.drawPath(path, paint);try {
                      Thread.sleep(1000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
  
              }
          }
  </code></pre>
  
  <p>this is kind of my code. I want to see each Path line draw after 1 sec of delay so I can see the drawing. But what exactly it does is pause the App for 1 sec and  then draw  the complete at once.</p>