问题调用无效在异步任务线程在Android的! [英] problem with calling invalidate in async task thread in Android !

查看:106
本文介绍了问题调用无效在异步任务线程在Android的!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打电话从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() code>。或者,使用 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).

这篇关于问题调用无效在异步任务线程在Android的!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆