title: getting a variable from a different thread android java
body: <p>I'm getting the error : android.os.networkonmainthreadexception. I found out, that that happens because i have to put internet requests on a thread other than main. I've searched for ways to put it on a seperate thread, and used this one, since i can understand it fairly well:</p>
  
  <pre><code>public void use() throws Exception
  {
      int a;
      Thread thread = new Thread(new Runnable()
      {
          @Override
          public void run()
          {
              try
              {
                  //do something
          a=32;
          //do smthn else
              }
              catch (Exception e)
              {
                  e.printStackTrace();
              }
          }
      });
  
      thread.start();
  int b= a;
  }
  </code></pre>
  
  <p>I make a new thread and put the network layer in it. The problem is, i can't get variables out of it. when i do like int b= a; as seen in the code it says : Variable (int a) is accesed from within inner class, needs to be declared final(int b). How can i get the int a outside from the variable in a easy way?</p>
  
  <p>All help is much appreciated :)
  Thanks.</p>