在 Android 的异步任务线程中调用 invalidate 时出现问题!
我试图从 asynctask 线程调用 invalidate() 。我收到此错误:
10-18 15:14:30.469: ERROR/AndroidRuntime(889): Caused by: android.view.ViewRoot$CalledFromWrongThreadException: 只有创建视图层次结构的原始线程才能触摸其视图。
我用过的线路是:
mainClass.myMapView.invalidate();//其中mainClass=主UI类
谁能建议我的错在哪里?
谢谢。
- 阿山
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能从 UI 线程(因此得名)以外的线程执行任何与 UI 相关的操作。您应该在
onPostExecute()
或onProgress()
中调用invalidate()
。或者,使用 runOnUiThread() (这基本上就是publishProgress()
/onProgress()
的作用)。You can't do anything UI-related from a different thread than the UI thread (thus its name). You should call
invalidate()
in eitheronPostExecute()
or inonProgress()
. Or, use runOnUiThread() (which is basically whatpublishProgress()
/onProgress()
does).