Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7431977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:22:56+00:00 2026-05-29T09:22:56+00:00

I want to make a background application in countdowntimer, that is if i am

  • 0

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.

//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;
    } 
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:22:56+00:00Added an answer on May 29, 2026 at 9:22 am

    You can use TimerTask Class for such purpose. It is same as thread , but allows you to perform a task based on Time Interval. you can also perform repeatable task in its run method.

    Please check simple example here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make an application that draws a layout with some background and
I am new to android development. I want to make one background application, so
i want to make application is always run in background even when we pulled
Background: I have started Android recently. I want to make an application for Android
I want to make a background image disappear. It works. But it fails when
I want to make a DIV background (which doesn't have a background color) flash
I want make interactive application where user launches it and can do various task
Is it possible to make a PHP application think that the server datetime is
I want to make an iphone application similar to some greeting cards application, where
hey I want to make a call from my application, so far I found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.