Hello how can i write this code in a separate threads because i have an intensive operations in my main thread.so i have to use an Async Activity and delegate the network intensive operation to 'doInBackground' method.but i don't know how to edit it
public void setImage(ImageView aView, final URL aURL) throws IOException {
final Bitmap bm = null;
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
URLConnection conn = null;
try {
conn = aURL.openConnection();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
conn.connect();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStream is = null;
try {
is = conn.getInputStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Bufferisation pour le t�l�chargement
BufferedInputStream bis = new BufferedInputStream(is, 8192);
// Cr�ation de l'image depuis le flux des donn�es entrant
bm = BitmapFactory.decodeStream(bis);
try {
bis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
};
task.execute(null, null, null);
// Fixe l'image sur le composant ImageView
aView.setImageBitmap(bm);
}
please help me thanks