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 7621733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:16:08+00:00 2026-05-31T04:16:08+00:00

There is a cancel() method in android to cancel a countdown timer. But since

  • 0

There is a cancel() method in android to cancel a countdown timer. But since the count down timer is running in a different thread, will the count down timer cancel, if I cancel it from inside of a button OnClickLitener().
The countdown timer was not started in the buttonOnclickListener, but It has to be cancelled inside the onClickListener().

  • 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-31T04:16:09+00:00Added an answer on May 31, 2026 at 4:16 am

    Here is an example of two buttons and a timer:
    The timer is running as a separate entity.
    You can start with one button and stop with another.

    package com.test;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.os.CountDownTimer;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.TextView;
    
    public class TimerTestActivity extends Activity {
    
        CountDownTimer cdt;
        TextView display;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main); 
    
            Button start = (Button) findViewById(R.id.startButton);
            start.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    setupCountDown();
                    cdt.start();
                }
            });
    
            Button stop = (Button) findViewById(R.id.stopButton);
            stop.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    cdt.cancel();
                }
            });
            display = (TextView) findViewById(R.id.display);
        }
    
        private void setupCountDown() {
            cdt = new CountDownTimer(10000, 1000) {
    
                public void onTick(long millisUntilFinished) {
                    display.setText("TICK " + millisUntilFinished/1000);
                }
    
                public void onFinish() {
                    display.setText("BUZZZZ");
                }           
            };
        }
    }
    

    and the main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <TextView
            android:id="@+id/display"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            />
    
        <Button
            android:id="@+id/startButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Start" />
    
        <Button
            android:id="@+id/stopButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Stop" />
    
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to prevent the doInBackground method/thread of an AsyncTask from starting
Is there any way to cancel or abort form creation from within the form's
There seem to be very different opinions about using transactions for reading from a
I am doing a simple Async operation with Android, but since I want to
(similar to Resettable Java Timer but there are some subtleties I need to explore)
Is there any way to cancel a RadioButton or CheckBox's change in state before
Is there a way to cancel a continuous replication using futon ? One of
I know there is a very similiar question ( JavaScript: How to select "Cancel"
There seems to be a similar question to this on here but with the
There are load balanced tomcat web servers. Every request could be served by different

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.