title: How to use runOnUiThread in a class?
body: <p>My code is designed to read a .txt file from a URL, and then display the text inside my textview. the problem is, I am using this code in a class. and getting this error- "cannot resolve method runOnUiThread". How do I fix this??</p>
  
  <pre><code>public class mydownloaderclass {
  
  // this method is called from MainActivity
  public static void checkForUpdates(Context context) {
      new Thread() {
          @Override
          public void run() {
              String path ="http://host.com/info.txt";
              URL u = null;
              try {
                  u = new URL(path);
                  HttpURLConnection c = (HttpURLConnection) u.openConnection();
                  c.setRequestMethod("GET");
                  c.connect();
                  InputStream in = c.getInputStream();
                  final ByteArrayOutputStream bo = new ByteArrayOutputStream();
                  byte[] buffer = new byte[1024];
                  in.read(buffer); // Read from Buffer.
                  bo.write(buffer); // Write Into Buffer.
  
                  runOnUiThread(new Runnable() {
                      @Override
                      public void run() {
                          TextView text = (TextView) findViewById(R.id.TextView1);
                          text.setText(bo.toString());
                          try {
                              bo.close();
                          } catch (IOException e) {
                              e.printStackTrace();
                          }
                      }
                  });
  
              } catch (MalformedURLException e) {
                  e.printStackTrace();
              } catch (ProtocolException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              }
  
          }
      }.start();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I tried using asynctask</p>
  
  <pre><code> public class readtextfile extends AsyncTask&lt;String, Integer, String&gt; {
      @Override
      protected String doInBackground(String... params) {
          String result = "";
          try {
              URL url = new URL("https://www.dropbox.com/myfile.txt");
              BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
              String line = null;
  
              while ((line = in.readLine()) != null) {
                  //get lines
                  result += line;
              }
              in.close();
          } catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
          return result;
      }
  
      @Override
      protected void onPostExecute(String result) {
          Toast.makeText(context, result, Toast.LENGTH_LONG).show();
      }
  }
  </code></pre>