如何执行后台作业更新UI的Andr​​oid观点 [英] How to execute background job that update UI view Android

查看:117
本文介绍了如何执行后台作业更新UI的Andr​​oid观点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程序,我有一个活动有意见。

In my Android application I have an activity with views.

要在活动开始或创造主要布局例如,我想启动去更新从主要布局为每5秒一个UI视图后台作业。

To the beginning of the activity or to the creation of main layout for example, I would like to start a background job that goes to update UI view from main layout for each 5 seconds.

所以,我对当下的策略是通过我的课,从观派生的runOnUiThread方法创作的主要布局过程中创造了Runnable。

So, my strategy for the moment was to create Runnable during creation of the main layout by using runOnUiThread method of my class that derives from View.

线程正常启动,但在线程我愿做一个等待5秒钟之前更新UI视图再次等待。我的问题是,当我使用视频下载,用户界面​​被阻止。

The thread starts correctly but in the thread I would like to do a wait for 5 seconds to wait before update UI view again. My problem is when I use Thread.sleep, the UI is blocked.

我猜Thread.sleep()方法阻止整个UI,但我不知道我该怎么做,必须解决这个问题。

I guess Thread.sleep() blocks the entire UI but I don't know how I must make to solve that problem.

所以我的问题是:什么是实现我想要的最好的解决方法(不使用的睡眠也许)

So my question is the following : what is the best solution to realize what I want (without using sleep perhaps) ?

推荐答案

以下链接对你所有的疑虑的答案:

The following link has the answer for all your doubts:

的Andr​​oid无痛线程

这篇关于如何执行后台作业更新UI的Andr​​oid观点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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