title: Passing variable into methods (Java)
body: <p>I'm new to Java, and I have a problem. I've copied some code off a tutorial for Android, and now I want to pass an integer variable into the method run(), so I can increment it for each loop and then catch it outside the background Thread. How would I do that?</p>
  
  <pre><code>int gg= 0;    
  Thread background = new Thread(new Runnable() {
                      public void run() {
                          try {
  
                              while (pBarDialog.getProgress() &lt;= 100) {
  
                                  Thread.sleep(100);
                                  gg++; // the increment here
                                  progressHandler.sendMessage(progressHandler
                                          .obtainMessage());
  
  
                              }
                              if (pBarDialog.getProgress() == 100) {
                                  pBarDialog.dismiss();
  
                              }
  
                          } catch (java.lang.InterruptedException e) {
                              // if something fails do something smart
                          }
                      }
  
                  });
            //catch gg here
  </code></pre>