views:

34

answers:

1
+1  Q: 

Thread on Android

Hi all, I have doubt on thread Life cycle in android.This is my scenario I have downloaded data from web and stored it in the DB.all this activity i have done using thread,once the activity finished i passed the object to handler and proceed . But my doubt is whether i need to stop the thread?

This is the Example

               showDialog(0);
              Thread  t=new Thread() 
                    {
                        public void run()
                            {

                            downloadFromNet();
                            }
                    };
                    t.start();


                     void downloadFromNet()
                      {
                          Message myMessage=new Message();
            myMessage.obj="SUCCESS";
            handler.sendMessage(myMessage);
                        }
           private Handler handler = new Handler()
       {
        @Override
        public void handleMessage(Message msg) {
              String loginmsg=(String)msg.obj;
              if(loginmsg.equals("SUCCESS")) 
              {
                  removeDialog(0);  
                  }
           };

Should I need to stop the Thread or Its lifecycle will be over?

+1  A: 

Android actually takes care of Thread housekeeping itself. You should not need to stop it manually as long as you don't start is as a daemon.

Here is the reference of Threads for Android.

Octavian Damiean