Table is no longer valid to operate on, on AsyncTask
<p>I'm having a real hard time to make Realm work on Async Task, and so far, I was not able to make it work.</p>

<p>So, this is basically what I'm trying to do:</p>

<pre><code>private class saveOnRealmAsync extends AsyncTask&lt;Void, Void, List&lt;Transactions&gt;&gt; {

    @Override
    protected List&lt;Transactions&gt; doInBackground(Void... Void) {
        //make a list of object to save on Realms
        return listObjectToSave; 
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        showProgressDialog();
    }

    @Override
    protected void onPostExecute(List&lt;Transactions&gt; listObjectToSave) {
        super.onPostExecute(transactionsList);
        Realm realm = Realm.getDefaultInstance();
        realm.beginTransaction();
        realm.copyToRealmOrUpdate(listObjectToSave);
        realm.commitTransaction();
        realm.close();

        hideProgressDialog();

        activity.finish();

    }
}
</code></pre>

<p>I'm got a </p>

<blockquote>
  <p>"java.lang.IllegalStateException: Illegal State: Table is no longer valid to operate on."</p>
</blockquote>

<p>on <code>realm.copyToRealmOrUpdate(listObjectToSave);</code></p>

<p>It works when I do this outside of an AsyncTask, but the problem is, some times, it take some times to get my list object ready to save.</p>

<p>What am I doing wrong? </p>