Well, but generally, it's not a solution. Try making your buffer size
content-length dependent:

totalSize = conn.getContentLength();
.....

byte data[] = new byte[totalSize/100];

This way you'll get exactly +1% update for download progress. For most
generic case I would suggets somethig line this:


totalSize = conn.getContentLength();
.....

tmpBufSize = totalSize/100;
byte data[] = new byte[tmpBufSize >= 1 ?tmpBufSize:1024];




On Mar 20, 1:24 pm, dsukhram <duanesukh...@gmail.com> wrote:
> Thanks Paul you were correct.  I increased the buffer size by 8 times
> and it worked.
>
> On Mar 19, 10:28 pm, Paul Turchenko <paul.turche...@gmail.com> wrote:
>
> > Try increasing your buffer size (or better, make it content-length-
> > dependent). It seems that UI theread reseives too much tasks to do and
> > this makes it other tasks to wait too long. This makes android show
> > ANR message. If this not helps, try dealing with download from your
> > own separate thread. This might help you find what's wrong. But IMHO,
> > it seems that somethig else makes your UI thread starve - this causes
> > ANR message.
>
> > On Mar 20, 12:29 am, dsukhram <duanesukh...@gmail.com> wrote:
>
> > > this is my inner class that handles the downloading and progressbar
>
> > > public class DownloadDBTask extends AsyncTask<Object, Integer, Object>
> > > {
> > > private int mProgress;
>
> > > public Object doInBackground(Object ...urls)
> > > {
> > > //download file
> > > int totalSize =0;
>
> > > try
> > > {
> > > URL urlFile = new URL("http://www.xxx.com/test.db";);
> > > URLConnection conn;
> > > conn = urlFile.openConnection();
> > > totalSize = conn.getContentLength();
>
> > > Log.i("INFO","total size of file "+totalSize);
> > > BufferedInputStream bis = new
> > > BufferedInputStream(urlFile.openStream());
> > > BufferedOutputStream bout = new BufferedOutputStream(new
> > > FileOutputStream(PATH+DB_NAME),1024);
> > > byte data[] = new byte[1024];
> > > int bufferSize =0;
> > > int currentSize = 0;
>
> > > while((bufferSize = bis.read(data)) != -1 )
> > > {
>
> > > currentSize +=bufferSize;
> > > bout.write(data,0,bufferSize);
>
> > > publishProgress((int) ((currentSize / (float) totalSize) * 100));
>
> > > }
>
> > > Log.i("INFO","Done downloading");
>
> > > bout.flush();
> > > bis.close();
> > > bout.close();
>
> > > }
>
> > > catch(IOException e)
> > > {
> > > Log.e("ERROR",e.toString());
>
> > > }
>
> > > return (new Object());
>
> > > }
>
> > > public void onPostExecute(Object result) {
>
> > > mProgressDialog.dismiss();
>
> > > }
>
> > > protected void onProgressUpdate(Integer... progress) {
>
> > > mProgressDialog.setProgress(progress[0]);
>
> > > }
>
> > > protected void onPreExecute(){
>
> > > showDialog(2);
>
> > > }
> > > }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to