I looked at a few other questions regarding a similar issue, and I figured out that I need to use the onProgressUpdate
method to change the message of ProgressDialog
.
For example, I have code like this that runs in the AsyncTask
's doInBackGround
(this is just a very small sample):
byte[] data = getBytesFromFile(image);
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
pictures.dia.setProgress(30);
pictures.dia.setMessage("Data beginning upload sequence...");
URL connectURL = new URL(this.base_url);
HttpURLConnection conn = (HttpURLConnection) connectURL.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "multipart/form-data, boundary=" + boundary);
DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
pictures.dia.setProgress(40);
pictures.dia.setMessage("Output Stream prepared...");
When I originally run thus, I get a Leaky Window error saying that I can't change dia
's message outside of AsyncTask
.
So my question is, how do I use onProgressUpdate
to set the message of dia
when dia
's progress reaches a certain number? (i.e., when dia
's progress = 30, make it say "Data beginning upload sequence...")
onProgressUpdate
must obviously always be checking dia
's progress (like a listener, I suppose)[if it doesn't already do this, how can I make it do this?]
publishProgress(new TaskProgress(10, "Beginning sequence..."));
in somerunnable
code. My runnable is called in thedoInBackground
method, but isn't physically in that method. Also, the runnable later calls another method from another class, where I can't usepublishProgress
. Any way around this? – Moonlighting