问题
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:
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).
来源:https://stackoverflow.com/questions/3960886/problem-with-calling-invalidate-in-async-task-thread-in-android