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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:37:48+00:00 2026-06-08T07:37:48+00:00

I am implementing a countup timer and I follow an example from StackoverFlow. In

  • 0

I am implementing a countup timer and I follow an example from StackoverFlow.
In my version, I will press the Begin button to start counting and the Stop button to stop.
But the problem is that the counting start immediately after i enter the activity.
Any idea how to make it the way i want?

public class StartActivity extends Activity
{
    Button beginRecordingButton;
    TextView timer;
    long startTime;
    long countup;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {super.onCreate(savedInstanceState);
        setContentView(R.layout.startactivity);
        beginRecordingButton = (Button) findViewById(R.id.BeginRecording);
        timer = (TextView) findViewById(R.id.timer);
        final Chronometer stopwatch = (Chronometer) findViewById(R.id.chrono);
        startTime = SystemClock.elapsedRealtime();
        stopwatch.setOnChronometerTickListener(listener);


        beginRecordingButton.setOnClickListener(new OnClickListener()
        {
            int counter = 0;


            public void onClick(View v)
            {

                if (counter % 2 == 0)
                {


                    stopwatch.start();
                    beginRecordingButton.setText("Stop");
                }
                if (counter % 2 == 1)
                {

                    stopwatch.stop();
                    beginRecordingButton.setText("Begin");
                }
                counter++;  //counter is used for knowing it is stop or begin

            }
        });
    }

    private OnChronometerTickListener listener = new OnChronometerTickListener()
    {

        public void onChronometerTick(Chronometer chronometer)
        {
            String text;
            countup = (SystemClock.elapsedRealtime() - chronometer.getBase())/1000;
            if(countup%60<10)
            {
                 text = (countup/60) + ":0" + (countup%60);
            }
            else
            {
                 text = (countup/60) + ":" + (countup%60);
            }

            timer.setText(text);
        }
    };
}
  • 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-08T07:37:49+00:00Added an answer on June 8, 2026 at 7:37 am

    I found the solution by doing follow:

    long test;
    
    test = (SystemClock.elapsedRealtime() - stopwatch.getBase())/1000;
    Log.i(TAG, = (SystemClock.elapsedRealtime() - chronometer.getBase()) / 1000 - test;
    
    basically String.valueOf(test));
    stopwatch.start();
    

    countup the idea is to subtract the passing time if i press the start button so it goes from 0

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

Sidebar

Related Questions

I implementing OLE DB provider for my custom database. It will be used from
when implementing a recursive function during development, i will use a counter and exit
Implementing the very first scala example I ran into some problems probably tipical for
Implementing a custom VM and I've come to use registers (these will store pointers
While implementing my own IFilter I found that most likely some consumers will require
While implementing the code from this question on my project I realized there's 3
Im implementing my own proto in Java, it will use a heartbeat over a
Am implementing the Ribbon toolbar button. On button click depending upon the schema name,
Implementing a custom Dependency Property on a Framework Element object causes my Visual Studio
Implementing the ScriptControlClass was extremely easy, unfortunately the side effects with the language implementation

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.