title: how to send data from thread to main activity java android
body: <p>I have a thread that i want to make some calculations and after that send it to the main activity of my program. how i can do that? </p>
  
  <p>the thread is </p>
  
  <pre><code>class RemindTask extends TimerTask {
      public void run() {
          flag = true;
          System.out.println(" Hello World!");
          for (int e=0; e&lt;2; e++){
              fileToReceive = fileparts.peek();
              System.out.println("fileToReceive "+fileToReceive);
              fileToReceive = fileparts.remove();
          }
          IntegerResult = 4;
          flag=false; 
      }
  </code></pre>
  
  <p>I want to send the IntegerResult to the main activity. this Timer is called from the activity from here </p>
  
  <pre><code>Timer timer = new Timer();
                         timer.schedule(new RemindTask(), 0,30000);
  </code></pre>
  
  <p>and after that i need to take the IntegerResult to the main activity 
  to the main so 
  tha main method is </p>
  
  <pre><code>int i=0;
  //IntegerResult = 4; here i need to take the result of the thread
  while (!fileparts.isEmpty()  ) { //&amp;&amp; !fileparts1.isEmpty() &amp;&amp; (flag == false) 
      String[] myStringArray = new String[IntegerResult];
      for (int e=0; e&lt;IntegerResult; e++){
          if (fileToReceive != null &amp;&amp; !fileparts.isEmpty() ){
              fileToReceive = fileparts.peek();
              myStringArray[e] =  fileToReceive;
              fileToReceive = fileparts.remove();
           } else {
              myStringArray[e] =  " ";
           }
           System.out.println("myStringArray["+e+"] " + myStringArray[e]);
      }
  </code></pre>