Creating background threadHi I new to android development. Presently i am working on android proj


Last Updated:

  1. mindus

    mindus Member This Topic's Starter

    Joined:
    Sep 7, 2010
    Messages:
    9
    Likes Received:
    0
    Hi

    I new to android development. Presently i am working on android project and i want to create a background thread which invokes the web service and get the data and insert in to array list. From foreground i need to fetch the data from array list and display in the list view.

    I tried to create a background thread. but the problem is all code has execute finally my background thread start executing.

    Can anybody have sample program for background thread or anybody give the sample idea for how to do the above concept?

    Thanks
    mindus
     

    Advertisement
  2. Kailas

    Kailas Member

    Joined:
    Aug 25, 2010
    Messages:
    19
    Likes Received:
    0
    I'm using a couple of threads in my game and I think you should be able to do it the same way I did.

    //make a class that extends Thread
    public class MyBackgroundThread extends Thread
    {

    //make a run function inside it that does what you want the thread to do
    @Override
    public void run()

    }

    //elsewhere in your code; where you want the thread to be created
    MyBackgroundThread thread = new MyBackgroundThread();
    thread.start();
    //I have this in the constructor of a class that is created when the game starts. After the constructor; the thread starts running the game loop.

    I hope that helps.
     
  3. tencent

    tencent Member

    Joined:
    Oct 1, 2010
    Messages:
    15
    Likes Received:
    0
    I think you need to look at threading with handlers.. here is a good example that essentially outlines what you need to do.

    Using threads and ProgressDialog | Hello Android

    Handlers are important because threads are not allowed to touch the ui directly. They have to go through handlers to process updates to the ui.
     

Share This Page

Loading...