title: How to execute android function sequentially?
body: <p>I make a game about 8Puzzle on android with AI using A* algorithm.
  Everything works fine but there is a problem, there are some function that is executed in parallel.
  What I want is the function is executed after another function is finished.</p>
  
  <p>Here is code:</p>
  
  <pre><code>if(AItype.equals("A*"))
  {
      DisableButton();
      DisableClickImageView();
      AStarSolver as = new AStarSolver();
      as.solvePuzzle(arr, GOAL); //Solve the puzzle
      displayResult(as.solutionPath); //display animation
      as = null;
  
      Toast.makeText(getApplicationContext(), "Finished", Toast.LENGTH_LONG).show();
      copySTARTtoArray();
      setImageResource();
      EnableButton();             
  }
  </code></pre>
  
  <p>I want text <strong>"Finished"</strong> is displayed after function <code>displayResult()</code> is finished but the text <strong>"Finished"</strong>
  show at the same time with  function <code>displayResult()</code>.</p>
  
  <p>How to solve this??</p>
  
  <p>Edit:</p>
  
  <p>Here is the code for displayResult();</p>
  
  <pre><code>public void displayResult(final Stack&lt;Node&gt; solutionPath)
  {
      Handler handler = new Handler(); 
      for (int i = 0; i &lt; solutionPath.size(); i++)
      {
          handler.postDelayed(new Runnable() { 
              public void run() { 
                      Node solNode = solutionPath.pop();
                      //solNode.NodeState.
                      tile00.setImageResource(solNode.getImageResourceBasedNodeState(0));
                      tile01.setImageResource(solNode.getImageResourceBasedNodeState(1));
                      tile02.setImageResource(solNode.getImageResourceBasedNodeState(2));
                      tile10.setImageResource(solNode.getImageResourceBasedNodeState(3));
                      tile11.setImageResource(solNode.getImageResourceBasedNodeState(4));
                          tile12.setImageResource(solNode.getImageResourceBasedNodeState(5));
                      tile20.setImageResource(solNode.getImageResourceBasedNodeState(6));
                          tile21.setImageResource(solNode.getImageResourceBasedNodeState(7));
                      tile22.setImageResource(solNode.getImageResourceBasedNodeState(8));  
              } 
          }, 800 * (i + 1));  
  
      }   
  }
  </code></pre>
  
  <p>It display the result of animation (Ex: tile0 to tile1)</p>