Download unexpected issue

  • Thread starter Thread starter Android Central Question
  • Start date Start date
A

Android Central Question

Dear Support,
I have an android app which is downloading the PDF from server,I am using
DownloadIntentService class for downloading, here I am using

sometime its downloading very fast while sometime very slow, I have checked the internet connection also , its fine, while download spped is fine but app is taking time to download

what could be the issue,

con = (HttpURLConnection) url.openConnection();
is = con.getInputStream();
fos = new FileOutputStream(path);
int lenghtOfFile = con.getContentLength();
byte data[] = new byte[51200];
Bundle b = new Bundle();
int upd;
long total=0;
while ((count = is.read(data)) != -1) {
total+=count;

// write data to file
fos.write(data, 0, count);
// send progress to MainActiivty through ResultReceiver
b.putString("progress", (int)((total*100)/lenghtOfFile)+"");

upd=(int)((total*100)/lenghtOfFile);
// Log.d("downloaded %: ", "" + (int)((total*100)/lenghtOfFile)+"");
// resultReceiver.send(CustomAdapterHome.RESULT_CODE, b);
 
Welcome to Android Central! Please be aware that this is an independent community forum, not an official support site. I moved your question to the Software Development forum, for more specific traffic.
 
First, unless you're downloading from something in your LAN, download speeds vary constantly - even from the same server. I've had 50% difference from try to try checking speed with a pretty local speed test server. More than "pretty local" and the speed can drop to 0 at times (even long enough to stop the download).

I don't see anything wrong with the code [I'm not that familiar with the "while (count = is.read(data)" - it may be a pleonasm, not requiring the != -1 - it won't have anything to do with the speed. I suspect that the difference is just the internet. Try measuring the speed 100 times, and see what the spread between fastest and slowest is.

Also, check logcat to see what else the device is doing during both slow and fast downloads. The system could be doing something behind the scenes that's slowing down the download.
 

Forum statistics

Threads
954,748
Messages
6,962,711
Members
3,163,120
Latest member
Morphey1