title: Check if a thread is running from the "mother" class
body: <p>In my Main Activity, I have a Thread that is doing <em>alot</em> of stuff, including adding some records to a database. In my second activity, which inherit from the Main Activity, I want to do a query to my database. But I need to check if the first thread in the Main Activity is finished, what I've done so far is:</p>
  
  <pre><code>public class History extends Main {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState); 
  
      if(!(MainThread.isAlive())) {
              getFromDatabase();
      }
  }
  }
  </code></pre>
  
  <p>This is my <code>getFromDatabase()</code> method</p>
  
  <pre><code>    pd = ProgressDialog.show(this, "Please Wait",
                  "Getting cases from database", false);
  
      Thread t = new Thread(this);
      t.start();
  </code></pre>
  
  <p>which will call this run method:</p>
  
  <pre><code>@Override
  public void run() {
  
      ArrayList&lt;Case&gt; c = db1.getAllCases();
      Message msg = handler.obtainMessage();
      msg.obj = c;
      handler.sendMessage(msg);
  }
  
  private Handler handler = new Handler() {
  
      @SuppressWarnings("unchecked")
      @Override
      public void handleMessage(Message m) {
          pd.dismiss();
          list = (ArrayList&lt;Case&gt;) m.obj;
          tempList = getCaseNumberToTempList(list);
          tempCaseList = createTempList(list);
  
          lv.setAdapter(new CustomAdapter(History.this, list));
          lv.setTextFilterEnabled(true);
      }
  };
  </code></pre>
  
  <p>But if I do so, the following line of code will crash my application, it will give a <code>NullPointerException</code>:</p>
  
  <pre><code>if(!(MainThread.isAlive())) {
              getFromDatabase();
      }
  </code></pre>
  
  <p>How can I be sure that that the first thread is finished with all the work before I query the database from my history activity? </p>