I have a very simple task, which I can't seem to do...

The application runs a background thread to process some files.
As it goes, I thought it'd be nice to just show the progress as it
happens.

My first thought was to have a Thread, and call append() on a TextView
from the activity as each file was processed.

That didn't work because of this error:
CalledFromWrongThreadException: Only the original thread that created
a view hierarchy can touch its views.

Ok, so I saw this tutorial, but I can't make it work:
http://android-developers.blogspot.com/2009/05/painless-threading.html

It looks like I should be able to do this:
private class updater extends AsyncTask {
        public TextView tv = null;
        protected Object doInBackground(Object[] args) {
                this.publishProgress("hello...");
                return((Object) this);
        }
        protected void onProgressUpdate(Object[] msgs) {
                if (msgs != null) {
                        String msg = msgs[0].toString();
                        trace(msg);
                }
        }
        private void trace(String msg) {
             if (tv != null)
                   tv.append(msg + "\n");
        }
    }
}

As it says in the tutorial:
    * You can specify the type, using generics, of the parameters, the
progress values and the final value of the task
    * The method doInBackground() executes automatically on a worker
thread
    * onPreExecute(), onPostExecute() and onProgressUpdate() are all
invoked on the UI thread
    * The value returned by doInBackground() is sent to onPostExecute
()
    * You can call publishProgress() at anytime in doInBackground() to
execute onProgressUpdate() on the UI thread
    * You can cancel the task at any time, from any thread

So that should work... I guess.

Problem: Calling publishProgress() steps into a series of binary-only
files, and never invokes onProgressUpdate().

Help? Anyone got a working example of onProgressUpdate()?

~
Doug.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to