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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:26:51+00:00 2026-06-15T16:26:51+00:00

This seems to be a common question, how do I pause a countdowntimer? I

  • 0

This seems to be a common question, “how do I pause a countdowntimer”?

I found this code which looks promising:

http://www.java2s.com/Open-Source/Android/Timer/multitimer-android/com/cycleindex/multitimer/CountDownTimerWithPause.java.htm

I’m just not sure how to implement it in code. I need to override the abstracted methods and extend the class. Can someone give me an idea how to do this?

  • 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-06-15T16:26:53+00:00Added an answer on June 15, 2026 at 4:26 pm

    Here is your layout

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="vertical"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
            >
        <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="0"
                android:gravity="center_horizontal"
                android:layout_marginBottom="40dp"
                android:layout_marginTop="20dp"
                android:textSize="27dp"
                android:id="@+id/txtView"/>
        <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_gravity="center">
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Start"
                    android:id="@+id/startButton"/>
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Stop"
                    android:id="@+id/stopButton"
                    android:layout_toRightOf="@id/startButton"/>
        </RelativeLayout>
    </LinearLayout>
    

    Here is your activity class

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TextView;
    import android.widget.Toast;
    
    public class MyActivity extends Activity implements View.OnClickListener {
    
        TextView txt = null;
        Button startButton = null;
        Button stopButton = null;
        CountDownTimerWithPause timer = null;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            txt = (TextView) findViewById(R.id.txtView);
            startButton = (Button) findViewById(R.id.startButton);
            stopButton = (Button) findViewById(R.id.stopButton);
    
            startButton.setOnClickListener(this);
            stopButton.setOnClickListener(this);
        }
    
        @Override
        public void onClick(View view) {
            if (view == startButton) {
                if (timer == null) {
                    initTimer();
                }
    
                timer.resume();
            }
    
            if (view == stopButton) {
                timer.pause();
            }
        }
    
        private void initTimer() {
            timer = new CountDownTimerWithPause(10000, 1000, false) {
                @Override
                public void onTick(long millisUntilFinished) {
                    Integer currentValue = Integer.valueOf((String) MyActivity.this.txt.getText());
                    MyActivity.this.txt.setText(String.valueOf(currentValue + 1));
                }
    
                @Override
                public void onFinish() {
                    Toast.makeText(MyActivity.this, "finish", Toast.LENGTH_SHORT).show();
                }
            };
    
            timer.create();
        }
    }
    

    Do not forget to copy CountDownTimerWithPause into your package.

    Works for me, BUT…

    I mention some bugs but it depends on your application. Maybe it’s OK for you. Bug is – when starting timer, it fires immediatelly. ‘So what?’ you might ask. Imagine you click Stop button when 3 and half seconds passed. So when you click Start button you expect half second pass before you see 4, but not in that class implementation.

    And there is some strange delay at the end of counting. I’d recommend to search for better implementation.

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

Sidebar

Related Questions

I know this a common question but everything I found seems to remove white
This seems to be a common question, but I've yet to find a very
If this question seems common to you, I apologise, I did a quick search
It seems this is a common question/problem but despite checking out a number of
This seems like it'd be a common question, but I cannot find it. Perhaps
This seems like it would be a common question, but none of the items
This seems like a common CSS question, but for some reason I cannot find
This seems to be a common question but somehow none of the answers I
Seems like this would be a common question, though I could not find it
This seems like a pretty common problem, but I haven't found any sort of

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.