problem with calling invalidate in async task thread in Android !

随声附和 提交于 2019-12-07 18:35:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!