Asyntask:在doInbackground为什么更新UI线程会遇到错误? [英] Asyntask: why update UI Thread in doInbackground will meet error?

查看:269
本文介绍了Asyntask:在doInbackground为什么更新UI线程会遇到错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我读 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

这篇关于Asyntask:在doInbackground为什么更新UI线程会遇到错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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