I'm a fairly new programmer so any advice would be appreciated. I have a class that runs an AsyncTask in a loop everytime it is called. The AsyncTask looks like this:
public class LoadImageTask extends AsyncTask<Void, Void, Void> {
Context c;
ViewHolder vh;
public Bitmap bm;
ViewGroup container;
LinearLayout layout;
public LoadImageTask(Context c, ViewHolder vh, ViewGroup container,
LinearLayout linlay) {
this.vh = vh;
this.c = c;
this.container = container;
this.layout = linlay;
}
protected Void doInBackground(Void... params) {
Tools tools = new Tools();
this.bm = tools.getAlbumart(this.c, vh.albumID);
return null;
}
protected void onPostExecute(Void param) {
vh.iv.setImageBitmap(this.bm);
this.layout.addView(this.container);
if (bm!=null) {
bm.recycle();
}
}
}
ViewHolder vh - class that holds 2 textviews and an Imageview
ViewGroup container - the container being used to inflate an xml design i've made (with 2 textviews and an ImageView)
LinearLayout linlay - a scrollview layout that I am adding the container to (to expand it based on the amount of elements I want in that view)
The bitmaps that I create as using way too much memory, so I want to recycle them, but every time I try to recycle them after I add the container to the layout, it says I am trying to use a recycled bitmap (when I'm clearly calling recycle after adding the container to the screen)... I'm stumped at this point. Any help would be nice.