Extending Thread


Last Updated:

  1. andywhoa

    andywhoa Well-Known Member This Topic's Starter

    Joined:
    May 15, 2010
    Messages:
    105
    Likes Received:
    13
    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

    Joined:
    Sep 14, 2009
    Messages:
    148
    Likes Received:
    26
    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...