Display progress bar while uploading image to Amazon server in Android
<p>I am trying to display a <code>progress bar</code> while uploading an image to the <code>Amazon server.</code> Everything works fine, just that the progress bar is not visible when the image is being uploaded to the server. This is what I have tried so far.</p>

<p><code>My Activity</code></p>

<pre><code>cameraBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

              //Take the picture for the first time.

               photoFileName += RandomStringUtils.randomAlphanumeric(5) + ".jpg";
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, getPhotoFileUri(photoFileName));

                if (intent.resolveActivity(getPackageManager()) != null) {
                    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
                }
            }
        }
    });



  protected void onActivityResult(int requestCode, int resultCode, Intent data) {

 if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {

    // progressBar.setVisibility(View.VISIBLE);

        if (resultCode == RESULT_OK) {

          Uri takenPhotoUri = getPhotoFileUri(photoFileName);
          Bitmap takenImage = BitmapFactory.decodeFile(takenPhotoUri.getPath());

            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            takenImage.compress(Bitmap.CompressFormat.JPEG, 50, bos);

         try {
                AmazonS3Client s3Client = new AmazonS3Client(
                        new BasicAWSCredentials(MY_ACCESS_KEY_ID, MY_SECRET_KEY));
                byte[] contentBytes = bos.toByteArray(); 

                InputStream is = new ByteArrayInputStream(contentBytes);

                Long contentLength = Long.valueOf(contentBytes.length);

                ObjectMetadata objectMetadata = new ObjectMetadata();
                objectMetadata.setContentLength(contentLength);

                PutObjectRequest putObjectRequest =
                        new PutObjectRequest(BUCKET_NAME,
                                photoFileName, is, objectMetadata);

             //progressBar.setVisibility(View.VISIBLE);

               PutObjectResult result = s3Client.putObject(putObjectRequest);

              // progressBar.setVisibility(View.INVISIBLE);

  }
</code></pre>

<p>This is what I have done so far. While uploading the <code>image</code> to the <code>server</code> the <code>phone screen</code> goes black(nothing works at this time) and returns to normal after like 10 seconds. </p>