title: AsyncTask check MainActivity for variable set before ending doInBackground
body: <p>I would like to check for a variable in MainActivity while an AsyncTask created from it is running in the background, then end the AsyncTask when this variable is set to a certain value let's say to true;</p>
  
  <p>MainActivity</p>
  
  <pre><code>    @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          new MyTask(this).execute();
      }
  </code></pre>
  
  <p>MyTask</p>
  
  <pre><code>
  public class MyTask extends AsyncTask&lt;Void, Void, Void&gt;
  {
      @Override
      protected Void doInBackground(Void... ignore)
      {
        //check for MainActivity variable then exit or PostExecute when this variable is set to true?
      }
  
  }
  </code></pre>