I am showing my upload progress using a ProgressDialog
in an AsycTask
but if the upload speed is less and the bar moves taking some time and my application shows application not responding error i.e wait or force close ..bt actually my work is going on and if I choose wait the application runs file..what should I do to remove this application not responding error, or can I increase the time in till so that it doe's show so fast?
in the doInBackground
method
.
.
.
.
.
.
int i;
byte[] buf = new byte[512];
while ((i = in.read(buf)) != -1) {
ou开发者_StackOverflowt.write(buf,0,i);
publishProgress(in.available());
System.out.println(i);
}
and int the progress upgrade method
protected void onProgressUpdate(Integer... values) {
// TODO Auto-generated method stub
super.onProgressUpdate(values);
if(a==0){
progressDialog.show();
}
a++;
int b=(int) (fil.length()-values[0]);
progressDialog.setProgress(b);
}
I think that the reason you are getting the ANR is that you are doing your long running task on the UI thread. If you move the blocking stuff onto another thread and notify the UI thread of the progress updates, you might find that the ANR disappears. Apologies if your long running task is already in the background (it is impossible to tell from your code)
You could try using an AsyncTask. This has the notification mechanism built in and manages the threading for you.
精彩评论