title: Android how to wait for code to finish before continuing
body: <p>I have a method called <code>hostPhoto()</code>; it basically uploads an image to a site and retrieves a link.
  I then have an other method to post the link to a website.</p>
  
  <p>Now the way Im' using this method is like this:</p>
  
  <pre><code>String link = hostPhoto(); //returns a link in string format
  
  post(text+" "+link); // posts the text + a link.
  </code></pre>
  
  <p>My problem is... that the <code>hostPhoto()</code> takes a few seconds to upload and retrieve the link,
  my program seems to not wait and continue posting, therefore im left with the link as null,</p>
  
  <p>Is there anyway i could make it get the link first... and then post?
  like some sort of onComplete? or something like that..
  i thought my method above would work but by doing Log.i's it seems the link is returned to the string after a second or so.</p>
  
  <p>UPDATE: This is the updates progress on my problem, im using a AsyncTask as informed, but the Log.i's error out showing the urlLink as a null... this means that the link requested from hostphoto never came back intime for the Logs..</p>
  
  <p>UPDATE 2: FINALLY WORKS! The problem was the Thread within the hostPhoto(), could someone provide me an explination why that thread would have caused this?
  Thanks to all who replied.</p>
  
  <pre><code>private class myAsyncTask extends AsyncTask&lt;Void, Void, Void&gt; {
      String urlLink;
      String text;
      public myAsyncTask(String txt){
  
          text=txt;
      }
  
      @Override
      protected Void doInBackground(Void... params) {
          urlLink=hostPhoto();
          //Log.i("Linked", urlLink);
          return null;
      }
  
      @Override
      protected void onPostExecute(Void result) {
  
          try {
              Log.i("Adding to status", urlLink);
              mLin.updateStatus(text+" "+urlLink);
              Log.i("Status:", urlLink);
          } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>hostPhoto() does this:</p>
  
  <pre><code>            String link;  new Thread(){
  
                  @Override
                  public void run(){
                      HostPhoto photo = new HostPhoto(); //create the host class
  
  
                      link= photo.post(filepath); // upload the photo and return the link
                      Log.i("link:",link);
                  }
              }.start();
  </code></pre>