How do I handle AsyncTask incompletion in fragments due to screen rotation
<p>I have an App which opens few fragments (actually 3) through a Fragment container (on Tab) and the first fragment uses AsyncTask to download feeds into the app.
The problem occurs when there is screen rotation - the application crashes.
I temporarily handle this problem by loading the data from PostExecute into private static variable but this problem can still occur when the user first enters the app.</p>

<p>This seems a very common or rampant problem but I've not been able to find outright solution here.
I do understand that this is because of configuration changes due to the screen rotation as the AsyncTask is running on a parallel thread to the UI thread.
I do refrain from using the Java threads/executor/executor service at this stage since there seem a ready-made tool in AsyncTask</p>

<p>I have been unable to interrupt the process in order to restart the activity or the fragment successfully and discard the initial subsequent AsyncTask calls..</p>

<p>In other words, how do I destroy the AsyncTask within a Fragment when there has been continuous configuration changes like Screen Rotation. Your help would be greatly appreciated.</p>

<pre><code>public class MolyListFragment extends Fragment {
public final static String MOLY_ARTICLE_DATA = "No Details";
private static final String TAG = "MOLY";
private static ArrayList&lt;MolyPg&gt; mMolyPgs = null;

@Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (mMolyPgs == null) {
        new MolyLoadTask().execute(getResources().getString(R.string.mly_feed));
    }
    else
        displayMlicles (mMolyPgs); //this displays the arrayList out of static mMolyPgs
}


private class MolyLoadTask extends AsyncTask&lt;String, Void, ArrayList&lt;MolyPg&gt;&gt; {
@Override
protected ArrayList&lt;MolyPg&gt; doInBackground(String... urls) {
        String myUrl = urls[0];
        ArrayList&lt;MolyPg&gt; myMlPgs = null;
    try {
            myMlPgs =  loadXmlFromNetwork(myUrl);
    } catch (MalformedURLException e) {
        Log.d(TAG, "MalformedURLException", e);
    } catch (IOException e) {
            getResources().getString(R.string.connection_error);
    } catch (XmlPullParserException e) {
            getResources().getString(R.string.xml_error);
    }

    return myMlPgs;
    }


    @Override
    protected void onPostExecute(ArrayList&lt;MolyPg&gt; result) {
        super.onPostExecute(result);

        Do some acrobatics here
    }
........    
    }
}
</code></pre>
