我首先创建一个异步任务来检索JSON数据。检索到的一个JSON对象是URL。
// This goes on my asynctask to get JSON data from the server
@Override
public void onPostExecute(JSONObject json) {
try {
String title = json.getString("title");
String description = json.getString("description");
String url = json.getString("url");
// Here comes the tricky part
Bitmap bitmap = Bitmap.createBitmap(100,100,Bitmap.Config.ARGB_8888);
new DownloadBitmap(bitmap).execute(url);
myArrayList.add(new DataContainer(title,description,bitmap));
// End of the tricky part
}catch(Exception e) {}
adapter.NotifyDataSetChange();
}
好的,你可以看到我需要bitmap
的引用发送到下载器类和listview的适配器的arraylist。
问题是下载程序类是这样的:
class DownloadBitmap extends AsyncTask<the 3 paramateres goes here>{
Bitmap bitmap;
public DownloadBitmap(Bitmap b) {
//Here I have a reference to the SAME bitmap object I added to the arraylist
bitmap = b;
}
@Override
protected void doInBackground(String... Params) {
// some code.....
// THIS IS THE PROBLEM, it re-initialize.
bitmap = BitmapFactory.decodeStream(inputstream);
}
我无法找到任何其他方法,如果可能的话,我想要一个独立的解决方案库,我公司对软件依赖有严格的政策。