在 Android 的异步任务线程中调用 invalidate 时出现问题!

发布于 2024-09-28 07:47:34 字数 373 浏览 1 评论 0原文

我试图从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情何以堪。 2024-10-05 07:47:34

您不能从 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 either onPostExecute() or in onProgress(). Or, use runOnUiThread() (which is basically what publishProgress() / onProgress() does).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文