How to run a background application in countdowntimer using threading concept?
<p>I want to make a background application in countdowntimer, that is if i am starting
the timer and comes out of that application, and going to another application then 
coming back to that same countdowntimer application. i want that timer to be 
running until i stop. I know about the methods involved in it, but i am not sure
about the threading concepts used in it.   </p>

<pre><code>//MyActivity.class

     import android.app.Activity;
     import android.content.Intent;
     import android.os.Bundle;
     import android.util.Log;
     import android.view.View;
     import android.widget.Button;
     import android.widget.TextView;

     public class MyappActivity extends Activity 
     {
    private static final String Tag = "Background_Timer";
    private Button start;
    private Button stop;
    private TextView tv;

    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        start = (Button) findViewById(R.id.button);
        stop = (Button) findViewById(R.id.button1);

        tv = (TextView) findViewById(R.id.text1);

        this.runOnUiThread(new Runnable() 
        {
            public void run() 
            {
                tv.setText(MyAppService.seconds + " Seconds Left");
            }
        });

    }

    public void onClick(View src) 
    {
        switch (src.getId()) 
        {
        case R.id.button:
            Log.e(Tag, "onClick: starting service");
            startService(new Intent(this, MyAppService.class));
            break;

        case R.id.button1:
            Log.e(Tag, "onClick: stopping service");
            stopService(new Intent(this, MyAppService.class));
            break;
        }
    }
        }

        //MyService.class

        import android.app.Service;
        import android.content.Intent;
        import android.os.CountDownTimer;
        import android.os.IBinder;
        import android.util.Log;
        import android.widget.TextView;

        public class MyAppService extends Service 
        {

    private static final String TAG = "My Service";
    private static boolean state;
    private static TextView TextTimer;
    public static String seconds;

    MyThread mt = new MyThread();

    @Override
    public void onCreate() 
    {

        CountDownTimer Myapp = new CountDownTimer(50000, 1000) 
        {
            public void onTick(long millisUntilFinished) 
            {
                TextTimer.setText("Seconds left: " + (millisUntilFinished)
                        / 1000);
            }

            public void onFinish() 
            {
                TextTimer.setText("Finished!");
            }
        };  
    }

    public void onStart(Intent intent, int startid) 
    {
        Log.d(TAG, "on-Start");
        mt.start();
    }

    public void onDestroy() 
    {
        Log.d(TAG, "on-Stop");
        mt.stop();
    }

    public static class MyThread extends Thread 
    {

        public void run() 
        {
            try 
            {
                while (state = true) 
                {
                    MyThread.sleep(500);
                }
            } 
            catch (InterruptedException e) 
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            };
        }
    }

    @Override
    public IBinder onBind(Intent intent) 
    {
        // TODO Auto-generated method stub
        return null;
    } 
        }
</code></pre>
