基本上我正在閱讀從文件的圖像字節我有一個循環,必須從文件中讀取近20個圖像,並在此循環中,我已使我的類的對象,它擴展了ASyncTask類,我是讀取字節並在畫布上繪製doItBackground()
方法並在onPostExecute()
方法上設置我的圖像。所以基本上異步20線程開始在後臺執行。現在的問題是它沒有顯示任何圖像。問題是在Android的ASyncTask類
任何人有任何想法如何處理多個AsyncTask類?這是我的代碼。
@Override
protected Void doInBackground(Void... params)
{
// Log.i("start background thread", "start background thread");
Set<Integer> keys;
keys = iTileListOffsets.keySet();
boolean found = false;
Object key[] = keys.toArray();
int k = 0;
for (int i=0; i < key.length && found==false ; i++)
{
k = (Integer) key[i];
MapTileHeader tileHeader = iTileListOffsets.get(k);
if (tileHeader.equalsWith(mapTile.getiMapTileHeader()))
{
found = true;
}
}
if(found)
{
try
{
synchronized (MapMaker.getSingletonObject())
{
fc.position(0);
input.skipBytes(k);
int tSizeOfTile = input.readInt();
mapTile.loadTileWithFileHeader(input, tSizeOfTile, headerBytesArray);
}
mapMaker.getBufferedTilesDataList().add(mapTile);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
byte imageTile[] = mapTile.getImageTilesBytes(); //bufferedTile.getImageTilesBytes();
if(mapTile.getImageTilesBytes() != null)
{
try
{
Bitmap tileBitmap = BitmapFactory.decodeByteArray(imageTile, 0, imageTile.length);
canvas.drawBitmap(tileBitmap, rect.left, rect.top, null);
tileBitmap = null;
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
// Log.i("ENDDDD background thread", "ENDDD background thread");
return null;
}
@Override
protected void onPostExecute(Void result)
{
// TODO Auto-generated method stub
super.onPostExecute(result);
Log.i("start POSTECEXCUTE thread", "start POSTECEXCUTE thread");
MyRect mapRect = aBufferArea.GetScreenRectangle(buffer, aScrnArea);
Bitmap smallBitmap = Bitmap.createBitmap(bitmap, mapRect.left, mapRect.top, mapRect.width, mapRect.height);
image.setImageBitmap(smallBitmap);
Log.i("ENDDDDD POSTECEXCUTE thread", "ENDDDD POSTECEXCUTE thread");
}
感謝