[問題] 網路下載東西時 前景影像不見
想請問各位大大
我寫了一個程式
主要是 show 了一張圖片後
開了一個thread去網路載圖
但是當檔案很大的時候
前景影像卻消失了! (神奇)
可以請問這是甚麼樣的問題嗎? QQ
謝謝大大們!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.163.3.187
推
09/18 13:46, , 1F
09/18 13:46, 1F
onCreate function:
ImageView imageView = (ImageView)findViewById( R.id.imageView1);
Bitmap bitmap = fileDealer.getImageBitmap(this);
imageView.setImageBitmap(bitmap);
onStart function:
new Thread( new Runnable(){
public void run(){
URL url = new URL("檔案超過1mb的連結");
URLConnection conn = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection)conn;
httpConn.connect();
if( httpConn.getResponseCode() == HttpURLConnection.HTTP_OK){
inputStream = httpConn.getInputStream();
}
}
}).start();
我有想過是不是因為thread在跑的時候吃了大部分的資源
所以main thread就沒時間輸出畫面? ~..~
※ 編輯: issuemylove 來自: 118.163.3.187 (09/18 14:16)
推
09/18 14:37, , 2F
09/18 14:37, 2F
推
09/18 18:12, , 3F
09/18 18:12, 3F
→
09/19 00:11, , 4F
09/19 00:11, 4F
→
09/19 11:44, , 5F
09/19 11:44, 5F
→
09/19 13:44, , 6F
09/19 13:44, 6F
→
09/19 13:48, , 7F
09/19 13:48, 7F
→
09/19 13:49, , 8F
09/19 13:49, 8F
→
09/19 18:58, , 9F
09/19 18:58, 9F
→
09/19 18:58, , 10F
09/19 18:58, 10F
→
09/19 18:59, , 11F
09/19 18:59, 11F
→
09/19 19:07, , 12F
09/19 19:07, 12F
我看官網AsyncTask好像也是說它比較適合跑short operation耶QQ
http://developer.android.com/reference/android/os/AsyncTask.html
AsyncTasks should ideally be used for short operations (a few seconds at the
most.) If you need to keep threads running for long periods of time, it is
highly recommended you use the various APIs provided by the
java.util.concurrent pacakge such as Executor, ThreadPoolExecutor and
FutureTask.
※ 編輯: issuemylove 來自: 118.163.3.187 (09/19 19:10)
推
09/19 20:06, , 13F
09/19 20:06, 13F
推
09/19 21:37, , 14F
09/19 21:37, 14F
→
09/19 21:46, , 15F
09/19 21:46, 15F
→
09/19 22:52, , 16F
09/19 22:52, 16F
→
09/20 01:27, , 17F
09/20 01:27, 17F
這是錯誤發生的code http://ppt.cc/BqB3 http://ppt.cc/SicJ
錯誤訊息跟上面的一樣 http://ppt.cc/lEC1
我不知道為什麼會有null產生~..~
因為跑小一點的檔案就可以 大的話就有null QQ|||
※ 編輯: issuemylove 來自: 118.163.3.187 (09/20 09:52)
※ 編輯: issuemylove 來自: 118.163.3.187 (09/20 09:56)
→
09/20 10:32, , 18F
09/20 10:32, 18F
→
09/20 10:33, , 19F
09/20 10:33, 19F
→
09/20 10:33, , 20F
09/20 10:33, 20F
→
09/20 10:34, , 21F
09/20 10:34, 21F