AsyncTask crashing on screen rotation
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/2620917/how-to-handle-an-asynctask-during-screen-rotation">How to handle an AsyncTask during Screen Rotation?</a>  </p>
</blockquote>



<p>What is the proper way to handle <code>AsyncTask</code> operations during a screen orientation change? </p>

<p>Currently I am overriding <code>onRetainNonConfigurationInstance()</code> and storing stuff inside of a hashmap and checking in <code>onCreate()</code> <code>if getNonConfigurationInstance() != null</code>... I read up on dev.android and may have missed something..</p>

<p>My <code>AsyncTask</code> is handling Internet tasks..fetching images etc... Below is my AsyncTask, as for my onRetainNonConfigurationInstance I am grabbing storing getText() results from TextViews as well as storing a String [] and ImageView inside a HashMap</p>

<p>I am starting the AsyncTask 
new DownloadImage().execute(imgarr);</p>

<p>private class DownloadImage extends AsyncTask{</p>

<pre><code>    @Override
    protected Drawable[] doInBackground(String[]... arg0) {
        // TODO Auto-generated method stub
        InputStream is = null;
        Drawable [] drawarr = new Drawable[arg0[0].length];
        int size = arg0[0].length;
        if(size &gt; 20){
            size = 20;
        }
        try {
            for(int i = 0; i &lt; size; ++i){
            is = (InputStream) new URL(arg0[0][i]).getContent();
            drawarr[i] = Drawable.createFromStream(is, "pic");
            }
        } catch (MalformedURLException e) {Log.v("AdImageDownload","DownloadImage AsyncTask Malformed URL",e.getCause());} 
        catch (IOException e) {Log.v("AdImageDownload","DownloadImage IOException",e.getCause());}
        catch(NullPointerException e){Log.v("AdImageDownload","DownloadImage IOException",e.getCause());}
        return drawarr;
    }

    @Override
    protected void onPostExecute(Drawable[] result) {
        // TODO Auto-generated method stub
        //img1.setImageDrawable(result);
        for(int i = 0; i &lt; result.length; ++i){
            img1 = (ImageView)findViewById(imgIds[i]);
            img1.setImageDrawable(result[i]);
        }
        super.onPostExecute(result);
    }

}
</code></pre>
