Possible Duplicate:
How to handle an AsyncTask during Screen Rotation?
What is the proper way to handle AsyncTask
operations during a screen orientation change?
Currently I am overriding onRetainNonConfigurationInstance()
and storing stuff inside of a hashmap and checking in onCreate()
if getNonConfigurationInstance() != null
... I read up on dev.android and may have missed something..
My AsyncTask
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
I am starting the AsyncTask new DownloadImage().execute(imgarr);
private class DownloadImage extends AsyncTask{
@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 > 20){
size = 20;
}
try {
for(int i = 0; i < 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 < result.length; ++i){
img1 = (ImageView)findViewById(imgIds[i]);
img1.setImageDrawable(result[i]);
}
super.onPostExecute(result);
}
}