Asyntask:在doInbackground为什么更新UI线程会遇到错误?线程、错误、Asyntask、doInbackground

由网友(稚久.)分享简介:当我读 asyntask 文件,他们说:不应该的doInbackground更新UI线程,因为在不同的线程doInbackground工作when I read document about asyntask, they say that: "should not" update UI thread in doInb...

当我读 asyntask 文件,他们说:不应该的doInbackground更新UI线程,因为在不同的线程doInbackground工作

when I read document about asyntask, they say that: "should not" update UI thread in doInbackground because doInbackground work on different thread.

这意味着:此操作将危险的,因为UI线程是不是线程安全的。我明白。但是当我尝试测试发生什么事时,我在此功能更新UI线程。我收到错误(但错误并不看起来不像,因为 aysnchonize ,而是因为我们不能做到这一点)

that means : this action will dangerous because UI Thread isn't thread-safe. I understand it. but when I try for test what happen when I update UI Thread in this function. I receive error: (but error doesn't not look like because aysnchonize, but because we CANNOT do it)

   (TextView)((Activity)context).findViewById(R.id.text)).setText("StackOverFlow");
//context: reference of context object of UI Thread

我请解释一下。难道我们不应该切不可

感谢:)

推荐答案

我有什么理解为止与Android是......

what I have understand so far with android is...,

我们的不能从后台线程更新UI线程。 可能是它的情况下,他们已经停止我们从后台线程更新用户界面。

we can't update UI thread from background thread. May be it is the case they have stopped us to update UI from background thread.

这其中的原因是很清楚的...... @ OS级别会有这么多线程将运行。

The reason for that is very clear... @ OS level there will be so many thread will be running.

和也 来自不同应用程序的不同的线程,而在这种情况下,这将是混乱的屏幕上,如果我们能够从BG线程更新UI

And also different thread from different application, And in that case It will be chaos on the screen, if we can update UI from bg-thread

阅读全文

相关推荐

最新文章