Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

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?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
312 views
Welcome To Ask or Share your Answers For Others

1 Answer

This may help u...

//on create

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

after on create

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);

    }
};  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...