问题调用无效在异步任务线程在Android的!线程、任务、问题、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)...

我想打电话从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).

    Copyright 2016-2020 新思维的学习:问题调用无效在异步任务线程在Android的!线程、任务、问题、Android、All Right Reserved 浙ICP备20029812号-1