为什么我的 Android 应用程序运行速度变慢?
我正在使用此代码显示来自互联网的多个图像
ImageView iv = new ImageView;
URL url = new URL(address);
InputStream content = (InputStream)url.getContent();
Drawable d = Drawable.createFromStream(content , "src");
iv.setImageDrawable(d)
,但应用程序运行速度变慢,为什么? 互联网连接是原因吗???或者因为我输入了几个输入流来显示每个图像???
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???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用 AsyncTask 或使用单独的线程异步创建 InputStream 和 Drawable.createFromStream(...) ,然后在完成后使用 Handler 更新 ImageView 。 AsyncTask 是首选。
http://developer.android.com/reference/android/os/AsyncTask.html
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