简体   繁体   中英

why my android application become slow in running?

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 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM