Do threads stop on their own in Android

78 views Asked by At

Im a little confused on to how threading works. I worked with them a while ago when I made a FTP client for one of my apps, but only used to it start downloads and refresh the file list, nothing to snazzy. But now, im going to be using it extensively for getting information form a JSON server and populating data. I have gotten it to work, but I want to make sure I am doing it right. Here is the code.

public void getGameList()
{
    new Thread(new Runnable() {
        public void run() {
            Looper.prepare();
            List<Game> mGames = new ArrayList<Game>();
            mApiHelper = new ApiHelper("");
            mGames = mApiHelper.getGames("name=Metal&&platform=Microsoft%20Xbox%20360");
            Message msg = new Message();
            msg.what = 1;
            msg.obj = mGames;
            mHandler.sendMessage(msg);
        }
    }).start();
}

Now, I dont need that thread to keep running, but from my impressions of threads, they just stay there until they are told to go away. Is that true? Do I need to wrap the code in something like a while loop like Ive seen in other examples? Or will this thread stop once it sees there is nothing else to do?

0

There are 0 answers