title: Creating threads in Android
body: <p>How to make a new thread and initiate start of SrcGrabber.grabSource() in the main file? And what type of thread should I use? Without another thread this code doesn't work.<br>
  In the main file I just need to do SrcGrabber.grabSource() and continue with returned mBuffer.toString().</p>
  
  <pre><code>public class SrcGrabber {
  private HttpGet mRequest;
  private HttpClient mClient;
  private BufferedReader mReader;
  
  private DocumentBuilder mBuilder;
  
  private StringBuffer mBuffer;
  private String mNewLine;
  
  public SrcGrabber() {
      mRequest = new HttpGet();
      mClient = new DefaultHttpClient();
      mReader = null;
  
      try {
          DocumentBuilderFactory factory = DocumentBuilderFactory
                  .newInstance();
          factory.setIgnoringComments(true);
          mBuilder = factory.newDocumentBuilder();
      } catch (ParserConfigurationException e) {
          e.printStackTrace();
      }
  
      mBuffer = new StringBuffer(2000);
      mNewLine = System.getProperty("line.separator");
  }
  
  public String grabSource(String url) throws ClientProtocolException,
          IOException, URISyntaxException {
      mBuffer.setLength(0);
  
      try {
          mRequest.setURI(new URI("http://www.bash.im"));
          HttpResponse response = mClient.execute(mRequest);
          mReader = new BufferedReader(new InputStreamReader(response
                  .getEntity().getContent()));
  
          String line = "";
          while ((line = mReader.readLine()) != null) {
              mBuffer.append(line);
              mBuffer.append(mNewLine);
          }
      } finally {
          closeReader();
      }
  
      return mBuffer.toString();
  }
  
  private void closeReader() {
      if (mReader == null)
          return;
  
      try {
          mReader.close();
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>}</p>