Вопрос

I have the following line of code to download a Bitmap:

bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());

But what happens if the download is interrupted mid-download? Will the connection stay open? If yes, should I start a timer when I start downloading the image, and cancel if the image is not downloaded within, say, 60 seconds?

The JavaDoc says nothing about an interrupted download:

openConnection() throws an IOException if an error occurs while opening the connection. getInputStream() throws an IOException if no InputStream could be created.

Это было полезно?

Решение

Two scenarios I can foresee,

  1. If the connection is interrupted it would throw an network exception.
  2. If the connection is interrupted and and the content is not downloaded completely, then decoding part might not work and it will also throw an exception
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top