我想打电话从asyntask线程无效()。我得到这个错误:
I am trying to call the invalidate() from asyntask thread. I am getting this error :
15 10-18:14:30.469:ERROR / AndroidRuntime(889):$ android.view.ViewRoot CalledFromWrongThreadException:所致。只有创建视图层次可以触摸其观点原来的线程
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.
我用的线是:
mainClass.myMapView.invalidate(); //其中mainClass =主UI类
mainClass.myMapView.invalidate();//where mainClass=main UI class
任何人都可以提出好心在我的过错?
Can anyone kindly suggest where my fault is ?
感谢。
- 阿赫桑
- ahsan
推荐答案
您不能做任何事情,从不同的线程比UI线程(因此它的名字)UI相关的。你应该叫在任
onPostExecute()
或 onProgress()。或者,使用 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 either onPostExecute()
or in onProgress()
. Or, use runOnUiThread() (which is basically what publishProgress()
/ onProgress()
does).
相关推荐
最新文章