开发者

why my android application become slow in running?

开发者 https://www.devze.com 2023-01-26 10:05 出处:网络
I\'m using this code to display severl images from the internet ImageView iv = new ImageView; URL url = new URL(address);

I'm using this code to display severl images from the internet

ImageView iv = new ImageView;
URL url = new URL(address);
InputStream content = (InputStream)url.getContent();
Drawable d = Drawable.createFromStream(content , "src"); 
iv.setImageDrawable(d)

but the application became开发者_StackOverflow中文版 slow in running why ?? does the internet connection is the reason ??? or because i input several input stream to display each image???


You should create the InputStream and Drawable.createFromStream(...) asynchronously, either using an AsyncTask or using a separate thread and then update the ImageView using a Handler once they are complete. AsyncTask is prefereable.

http://developer.android.com/reference/android/os/AsyncTask.html

0

精彩评论

暂无评论...
验证码 换一张
取 消