title: progressBar not updating with setProgress
body: <p>I am trying to process some files and it takes some time, so I would like to use a progressBar while the operation is being performed. In my activity, I have a button which starts the processing, when I press on it, the progressBar does not update and after a while the operation is complete and I see the result of the processing (so the function is properly called and act as expected). </p>
  
  <p>The progressBar is visible, it just does not update. I have displayed <code>getProgress()</code> in the log and the value increases, only the actual progressBar does not update.</p>
  
  <p>The function which should update the progressBar:</p>
  
  <pre><code>private byte[] processFiles() throws ExecutionException, InterruptedException {
          //Init things
          final ArrayList&lt;String&gt; fileNames = getFileList();
          progressBar.setVisibility(View.VISIBLE);
          progressBar.setMax(fileNames.size());
          progressBar.setIndeterminate(false);
  
          for (int i = 0 ; i&lt;fileNames.size(); i++) {
              //Do stuff on files
              progressBar.setProgress(i+1);
              Log.d("CurrentActivity", String.valueOf(progressBar.getProgress()));
          }
          return bos.toByteArray();
      }
  </code></pre>
  
  <p>In the <code>onCreate()</code>:</p>
  
  <pre><code>progressBar = (ProgressBar) findViewById(R.id.progressBar);
  progressBar.setIndeterminate(false);
  </code></pre>
  
  <p>I have also tried as displayed in the <a href="https://developer.android.com/reference/android/widget/ProgressBar.html" rel="nofollow noreferrer">android developer tutorial</a> using a Thread but with no success (though I did not use a while loop but a for loop, but figured it shouldn't matter).</p>
  
  <p>Can anyone help me figure out the problem?</p>
  
  <p>Note I have also tried to use this before each update as suggested in some other answers:</p>
  
  <pre><code>progressBar.setProgress(0);
  progressBar.setMax(fileNames.size());
  </code></pre>
  
  <p>Edit, here is my onClickListener:</p>
  
  <pre><code>fileButton.setOnClickListener(new View.OnClickListener(){
          @Override
          public void onClick(View v) {
              // Init things
              try{
                  new Thread(new Runnable() {
                      public void run() {
                          try {
                              outStream = new FileOutputStream(path);
                              outStream.write(processFiles());
                              outStream.close();
  
                              runOnUiThread(new Runnable() {
                                  @Override
                                  public void run() {
                                      //stuff that updates ui
  
                                  }
                              });
                          } catch (ExecutionException e) {
                              e.printStackTrace();
                          } catch (InterruptedException e) {
                              e.printStackTrace();
                          }
                      }
                  }).start();
  
              }catch(Exception e){
                  e.printStackTrace();
              }
          }
      });
  </code></pre>
  
  <p>Now the progressBar works but using processedFile fails, it is an image that I display with Glide, it worked well before but now it doesn't display anything.</p>
  
  <p>Edit 2: using <code>runOnUiThread</code> for all UI update worked like a charm and fixed my new issue.</p>