Threading problem

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Threading problem

Postby sanyiii » Wed Feb 17, 2010 10:27 am

Hi everybody,

I have some threading problems:
I start an AsyncTask from the Activity, which downloads some files from the internet, and when it finished it notifies some listeners. These listeners creates some new View objects. When these views are created, i start an other AsyncTask from the constructor. This AsnycTask notifies an other listener (as the previouse one), which touches the View's child components. But at this point, a get an exception: "Only the original thread that created a view hierarchy can touch its views."

If i start an AsyncTask from a View, it's not running on UI thread? Or using the listener is not the best way? The listeners are implemented in the custom view classes.
sanyiii
Developer
Developer
 
Posts: 42
Joined: Wed Jun 10, 2009 9:58 am

Top

Postby mrco » Thu Feb 18, 2010 1:15 pm

doInBackground method runs in different thread, but onProgressUpdate runs on UI thread.
So you should call publicshProgress method from doInBackground. Show your AsyncTask class code.
mrco
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Jan 15, 2010 11:31 am
Location: 2V Software

Postby sanyiii » Fri Feb 19, 2010 9:42 am

Hi mrco!

I have modified my code, and i use the onProgressUpdate to update ImageView objects, and it's working fine now. Previously, i did it in the doInBackground method and that was wrong.

Thanks for your help!
sanyiii
Developer
Developer
 
Posts: 42
Joined: Wed Jun 10, 2009 9:58 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 11 guests