title: Android: Use callback method of AsyncTask class to change Activity
body: <p>I use AsyncTask to perform some data load over http requests in background. The http request use a session variable. This variable can become invalid and the http request will return an error.
  In this case the user have to relogin.</p>
  
  <p>So, can I just use something like this:</p>
  
  <pre><code>protected void onPostExecute(IData data) {
              //
              // !!On Error data object is null!!
              // 
      if (mCallback != null) {
          mCallback.onTaskComplete(data);
      }
  }
  </code></pre>
  
  <p>And in the Activity which implements the Callback interface I just check if the data object is null and change the Activity to the "MainActivity" Login form.</p>
  
  <pre><code>    public void onTaskComplete(IData data) {
      if (data == null) {
          Intent intent = new Intent(ReadDataActivity.this, MainActivity.class);
          deleteCurrentSavedSession();
          startActivity(intent);
      } else {
             // Do something with the data
          }
      }
  </code></pre>
  
  <p>Is this a bad idea? Should I better use <code>ExecutorService</code> and execute it as a "normal" thread which checks if the session is still valid?</p>
  
  <pre><code>ExecutorService executor = Executors.newFixedThreadPool(2);
  executor.execute(sessionCheckWorker);
  executor.shutdown();
  while (!executor.isTerminated()) {
  
  }
  // Wait until session check task is finished and decide which Activity to load
  </code></pre>
  
  <p>Best Regards</p>