使用线程运行code和更新UI的Andr​​oid [英] Using a Thread to run Code and update UI Android

查看:136
本文介绍了使用线程运行code和更新UI的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用一个线程来运行一些$ C $下连续的,同时运行的应用程序,使用它提供的信息定期更新应用程序的UI。

How do I use a thread to run some code continuously whilst an Apps running, using the information it gives to periodically update the UI of the App.

具体的线程将运行一些code通过一个文本文件,以便找到坐标这会然后用在UI上一个PNG绘制搜索。这将自动更新说,每一秒,也许每半秒,并会清除然后将图像重绘点。

Specifically the thread would run some code that searches through a text file in order to find co-ordinates which would then be plotted over a PNG on the UI. This would update automatically say every second maybe every half second, and would clear the image then redraw the points.

我如何首先建立线程,然后第二个所有的从线程信息发送回用户界面,并把它更新吗?

How do i first of all set up the thread then second of all send information from the thread back to the UI and have it update?

任何例如code将是巨大的,或者你已经遇到的任何信息给例如code。我并不想这样做,此刻最好的办法,只是试图破解它在一起,所以如果你知道这样做不觉得害怕分享简单和快速的(但可怕的)的方式。

Any example code would be great or any information you've come across that gives example code. I'm not trying to do it the best way at the moment, just trying to hack it together, so if you know easy and quick (but awful) ways of doing this don't feel afraid to share.

推荐答案

这可以帮助ü...

//上创建

主题currentThread =新主题(本);
        currentThread.start();

Thread currentThread = new Thread(this); currentThread.start();

在上创建

public void run() {
    try {
        Thread.sleep(4000);

        threadHandler.sendEmptyMessage(0);
    } catch (InterruptedException e) {
        //don't forget to deal with the Exception !!!!!
    }
} 

private Handler threadHandler = new Handler() {
    public void handleMessage(android.os.Message msg) {      


        Intent in = new Intent(getApplicationContext(),****.class);
        startActivity(in);

    }
};  

这篇关于使用线程运行code和更新UI的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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