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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:54:07+00:00 2026-06-14T10:54:07+00:00

I have an activity in which I want to track the time elapsed between

  • 0

I have an activity in which I want to track the time elapsed between two actions(for example startAction and endAction). I’ve used the following code to implement a timer that increments every 500 ms after the user presses the button for startAction:

TextView dayTimer = (TextView)findViewById(R.id.tvDayTimer);
long startTime;
class DayTimer extends TimerTask {

             @Override
             public void run() {
                 BBCAndroid.this.runOnUiThread(new Runnable() {

                  
                     public void run() {
                        long millis = SystemClock.elapsedRealtime() - startTime;
                        int seconds = (int) (millis / 1000);
                        int minutes = seconds / 60;
                        seconds     = seconds % 60;

                        dayTimer.setText(String.format("%d:%02d", minutes, seconds));
                     }
                 });
             }
        };


      startDayButton.setOnClickListener(new View.OnClickListener() {
            
            public void onClick(View v) {
                // TODO Auto-generated method stub
                
                            startTime = SystemClock.elapsedRealtime();
                        timer.schedule(new DayTimer(),  0,500);
                        LoginResult.DayState = 1;
                        startDayButton.setEnabled(false);
                        endDayButton.setEnabled(true);
            }
        });

Now my problem is that, if I exit the application the timer stops. How can I make it run even when the user is out of the app?
In summary, I need a timer that counts even if the app is closed.

  • 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-14T10:54:08+00:00Added an answer on June 14, 2026 at 10:54 am

    You can start a Service and it will be up and running even if your application is closed.

    Here is a good tutorial.

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

Sidebar

Related Questions

I have a phonegap activity which I want to start via a button press:
I have an Activity which uses a Fragment . I simply want to pass
So I have this class which extends an activity. But I want to draw
I have an activity which is going to switch around between several views, and
I have an activity which needs to make two remote server calls. The first
I have an activity which uses two Loaders. Each of them returns different type
I have an activity which I want to show ListView with list of topics,
I have an Activity which I want to be finished when user rotates the
I have an activity which shows an image (ViewCollection.java). I want to only create
I have a activity which calls a webservice and does xml parsing. i want

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.