title: How can I ensure an AsyncTask is completed before my activity is killed?
body: <p>I'm getting an <code>Unable to destroy activity xxx: android.database.sqlite.SQLiteException: unable to close due to unfinalised statements</code> error while my activity is being destroyed.  I presume this is because I'm performing database operations from within AsyncTasks and they are somehow being killed before completion. </p>
  
  <p>How can I ensure that my <code>AsyncTasks</code> actually complete before the activity is stopped?  Incidentally, I thought that an <code>AsyncTask</code> can't be explicitly killed without the <code>AsyncTask</code> agreeing to do so by checking.  </p>
  
  <p>It may be relevant that this error is occurring during Robotium integration testing.  I suspect it's happening after the test is completed and the test calls <code>Robotium.finishOpenedActivities()</code>.   My guess is that somehow the <code>AsyncTask</code> is being forcefully killed mid-execution if this is possible (though I don't explcitly support cancellation in my <code>AsyncTask</code> implementation).   Additionally, I use OrmLite for my database access.</p>