views:

18

answers:

1

Hi Everyone,

I am trying to call the invalidate() from asyntask thread. I am getting this error :

10-18 15:14:30.469: ERROR/AndroidRuntime(889): Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

The line I have used is :

mainClass.myMapView.invalidate();//where mainClass=main UI class

Can anyone kindly suggest where my fault is ?

Thanks.

- ahsan

+1  A: 

You can't do anything UI-related from a different thread than the UI thread (thus its name). You should call invalidate() in either onPostExecute() or in onProgress(). Or, use runOnUiThread() (which is basically what publishProgress() / onProgress() does).

Felix