title: Android Dev - Run top command output to TextView
body: <p>I have been reading a lot this forum , and it help me a lot to setup my application , however , I do have another problem now , what I am trying to do is to display the "top" command output in a textview.
  So layout is basically two buttons ( Start and Stop ) and a textView, and I have read here that I have to use an async task to run the command , up to here fine , now the problem is how to parse the output in order to display it correctly ? 
  The result I want is a small textview displaying the top command result ( same output as running the command in a terminal ) </p>
  
  <pre><code>public class Async extends AsyncTask&lt;String, String, Void&gt;
  {
  private View rootView;
  private Activity rootAct;
  public Async(View view,Activity act) {
      // TODO Auto-generated constructor stub\
      View rootView = view;
      rootAct = act;
  }
  
  
  @Override
  protected void onPreExecute() {
      Log.d("PRE-EXECUTE", "OK");
  }
  
  
  
  @Override
  protected void onCancelled() {
      Log.d("ON CANCEL", "OK");
  }
  
  
  @Override
  protected Void doInBackground(String... params) {
      //Execution en BackGround
      Log.d("BACKGROUND", "START");
      Log.d("BACK PARAM 0", params[0]);
      Log.d("BACK PARAM 1", params[1]);
  
          try {
              // Executes the command.
              Process process = Runtime.getRuntime().exec("top");
              // Reads stdout.
              // NOTE: You can write to stdin of the command using
              //       process.getOutputStream().
              BufferedReader reader = new BufferedReader(
                      new InputStreamReader(process.getInputStream()));
              int read;
              char[] buffer = new char[4096];
              StringBuffer output = new StringBuffer();
              while ((read = reader.read(buffer)) &gt; 0) {
                  output.append(buffer, 0, read);
                  publishProgress(output.toString());
  
  
              }
              reader.close();
  
  
  
              return null;
  
          } catch (IOException e) {
              throw new RuntimeException(e);
          }
      }
  
  
  
  @Override
  protected void onProgressUpdate(String... values) {
  
      Log.d("UPDATE", "START");
      Log.d("RESUL", values[0]);
  
      TextView sortie = (TextView) rootAct.findViewById(R.id.txt_output);
  
  
          sortie.setText(values[0]);
  
  
  
  
      Log.d("UPDATE", "STOP");
  
  }
  
  @Override
  protected void onPostExecute(Void result) {
      Log.d("POSTEXE", "OK");
  
  }
  
  }
  </code></pre>
  
  <p>Therefore , what I would like is my textView to display the top command result and update everytime a new "starting" line exist , well not sure it is very clear , in fact the easier example would be open a terminal command on your phone type top in it and I would like the exact same output ...</p>
  
  <p>I hope someone will be able to help me on that project ! ( and sorry for my horrible english , I'm french :) ) </p>
  
  <p>Best Regards, </p>
  
  <p>EDIT : In fact, I just need a way to read the buffer and to append line to my output except if there is 3 "\n" in a row , is it possible ?</p>