我試圖在顯示啓動畫面時從Internet中讀取17個圖像。但是,使用以下代碼,在處理過程中根本不會顯示啓動畫面。它變黑,完成並轉移到下一個活動。我認爲在處理代碼足夠好之前調用setContentView,但顯然不是。Android UI在處理其他數據時未顯示
我錯過了什麼?
感謝您的幫助。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
// read the bitmaps
// Open a new URL and get the InputStream to load data from it
// Start reading the XML and filling the arrays
for (int i=0; i<16; i++) {
try {
URL aURL = new URL (districtImage[i]);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
// Buffered is always good for performance
BufferedInputStream bis = new BufferedInputStream(is);
districtBitmap[i] = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
}
catch (IOException e){
Log.e ("DEBUGTAG","Cannot load remote image", e);
}
}
... some more code to transit to next activity...
}
感謝您的快速回復。讓我看看並回來。 – MikeC 2011-04-13 15:01:43
通讀AsyncTask。這是要走的路。謝謝 – MikeC 2011-04-14 02:29:20