Download unexpected issue

  • Thread starter Android Central Question
  • 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);
 

B. Diddy

Senior Ambassador
Moderator
Mar 9, 2012
165,726
4,893
113
Visit site
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.
 

Rukbat

Retired Moderator
Feb 12, 2012
44,529
28
0
Visit site
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
943,816
Messages
6,920,176
Members
3,159,246
Latest member
RomeoCatcher