1. Check out our companion app, Forums for Android! Download from Google Play

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

Discussion in 'Application Development' started by mindus, Oct 14, 2010.

  1. mindus

    mindus Member
    Thread Starter
    5

    Sep 7, 2010
    9
    0
    5
    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
    15

    Aug 25, 2010
    19
    0
    15
    Australia
    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
    15

    Oct 1, 2010
    15
    0
    15
    Programmer
    Gainesville, FL
    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...