Dusan,

For your code to work, do two things:

- Take out the Looper stuff from your worker thread. Looper.loop() goes into a loop that de-queues and processes messages until someone calls quit(). In your code, it keeps running forever after parsing is finished, I don't think you intended that. Simply exit your worker thread's run(), allowing the worker thread to terminate.

- Since the parse tracker is called from the same worker thread, use a posted runnable to switch the call to setProgress() to the UI thread.

And to answer your more broad question. The Android UI framework is not thread safe, and assumes that all UI calls are made from the main thread. However, this is not enforced in the code, at least not consistently for each and every UI related method. This limitation is documented, and it's assumed that developers read the docs and follow it.

Sometimes your code gets lucky and calling a UI-related method from a non-UI thread works. Other times (may be same application, same input data, same phone, only a new debug/run session) it may not get so lucky and crash, do nothing, do the wrong thing - in general, it's unpredictable.

A side note - these kinds of issues should be easier to diagnose on one of the upcoming dual-code tablet devices with Honeycomb. In my experience, a multi-threaded program that has threading issues (lack of synchronization, deadlocks, etc.) often "gets lucky" and works fine in a preemptive, uni-core environment, but has a much higher chance of hitting those problems on a multi-core system.

-- Kostya

31.01.2011 2:13, skrat ?????:
I have following code http://pastie.org/1513146, and while setProgress method works, onParsed doesn't. onParsed has to be called from Handler message because it accesses progressbar view from different thread. setProgress is called from different thread as well (thread running ParseTracker.update), also accesses progressbar view, but works without Handler. Am I missing something about accessing views from different threads? --
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


--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

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