1
ImageDownloadServiceで作業しています。問題は、それが私のアプリからイメージを連続的にダウンロードして、私の電話をハングすることです。私は、ダウンロードサービスが多すぎるリソースを使用していると考えています。特定のRAM使用量を超えた場合、サービスが遅くなるようにしたい。 リソース使用量に制限を設ける方法を教えてもらえますか?イメージダウンロードサービスリソースの超過使用
URL url = new URL(imageUrl));
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream is = connection.getInputStream();
String imageName = "IMAGE_" + System.currentTimeMillis() + ".png";
File image = new File(directoryPath, imageName);
FileOutputStream out = new FileOutputStream(image);
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = is.read(buffer)) > 0) {
out.write(buffer, 0, bytesRead);
}
is.close();
out.flush();
out.close();
connection.disconnect();
イメージを読み込むためにグライドのようなライブラリを使用してみてください。 – YakuZa
3番目の部分ライブラリを使用したくない場合は、[DownloadManager](http://developer.android.com/intl/ru/reference/android/app/DownloadManager.html)を使用して、 – Alexander