title: Block thread while uploading picture to Amazon S3 on Android
body: <p>Is there a way to block the current thread and wait while the picture is uploaded to S3?</p>
  
  <p>My code for uploading to the S3 is already running in a Android service in its doInBackground() method (with other network calls that have to be in specific order), so it's off the main UI thread. I just want to know when the uploading is done, so I can dismiss notification and show to user that everything is uploaded/done.</p>
  
  <p>I'm using SDK v2, like this:</p>
  
  <pre><code>TransferUtility transferUtility = new TransferUtility(s3, ctx);
  TransferObserver obs = transferUtility.upload(
              S3BucketNamePhotoTEST,
              imageId + ".jpg",
              file, new ObjectMetadata());
  obs.setTransferListener(new UploadListener(dbHandler, ctx, imageId));
  </code></pre>
  
  <p>Where UploadListener is a class implementing TransferListener, where in onStateChanged() method we can detect when the upload is finished:</p>
  
  <pre><code>public void onStateChanged(int id, TransferState state) {
          if (state == TransferState.COMPLETED) {
          //do something here!
          }
  }
  </code></pre>
  
  <p>That's not what I need, because my service call will be long done when that onStateChange() callback fires.</p>
  
  <p>But looking at SDK v1 (that's now mostly deprecated), there was a way to block it, with:</p>
  
  <pre><code>TransferManager tx = new TransferManager(
             credentialProviderChain.getCredentials());
  Upload myUpload = tx.upload(myBucket, myFile.getName(), myFile);
  ...
  // Or you can block the current thread and wait for your transfer to
  // to complete. If the transfer fails, this method will throw an
  // AmazonClientException or AmazonServiceException detailing the reason.
  myUpload.waitForCompletion();
  </code></pre>
  
  <p>This waitForCompletion() method is just what I need, but can't get to it with the newer API.</p>
  
  <p>Any solutions?</p>