1. Check out our app, Forums for Android! Download and leave feedback here!

Extending Thread

Discussion in 'Application Development' started by andywhoa, Jul 21, 2010.

  1. andywhoa

    andywhoa Well-Known Member
    Thread Starter
    38

    May 15, 2010
    105
    13
    38
    Software Engineer
    West Des Moines, IA
    Hi,

    I have a class I've created that extends Thread. This class calls a web service that returns a bunch of data. I'd to populate a member variable back in my Activity with this data as well as update the list on the Activity with this data. How can I achieve this? I've found an example to do it if you define the thread in the Activity class, but I have a separate file that extends Thread here. Could I get some assistance?

    Thank you
     

    Advertisement

  2. markb

    markb Well-Known Member
    63

    Sep 14, 2009
    148
    26
    63
    Software Developer (Java, C, Web, Unix)
    Birmingham, UK
    You can only update GUI widgets in the GUI thread. So your other non-GUI thread needs to send a message back to the GUI thread through a Handler.

    You create a Handler in the GUI thread and pass it to your non-GUI thread. Your non-GUI thread can then send messages back to the GUI thread, and that can respond by updating widgets as required.

    See the following:

    Common Tasks and How to Do Them in Android | Android Developers

    Rise Software Online: Tutorials for developers - Advanced's blog: Threading using AsyncTask and Thread/Handler

    Creating Dialogs | Android Developers
    (Look down the page for Handler)
     
    andywhoa likes this.

Share This Page

Loading...