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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:35:56+00:00 2026-06-01T14:35:56+00:00

My timer code is: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initializer(); fire.setOnClickListener(this); }

  • 0

My timer code is:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    initializer();
    fire.setOnClickListener(this);
}

private void initializer() {

    minute = (EditText) findViewById(R.id.etMinute);
    seconds = (EditText) findViewById(R.id.etSeconds);
    fire = (Button) findViewById(R.id.bFireTimer);
    Remain=(TextView)findViewById(R.id.tvRemain);
}



@Override
public void onClick(View v) {
    switch (v.getId()) {

    case R.id.bFireTimer:

                min=minute.getText().toString();
                sec=seconds.getText().toString();
                int MIN= Integer.parseInt(min);
                int SEC=Integer.parseInt(sec);
                long TIME= (MIN*60)+SEC;
                timercount =  new MyCount(TIME * 1000, 1000);
                timercount.start();


        break;
    }

}

public class MyCount extends CountDownTimer {

     public MyCount(long millisInFuture, long countDownInterval) {
          super(millisInFuture, countDownInterval);
      }

      @Override
      public void onFinish() {
          //some script here
      }

      @Override
      public void onTick(long millisUntilFinished) {

       //some  script here 
         int remseconds=(int)millisUntilFinished/1000;
        int remminuts=remseconds/60;
            remseconds= remseconds%60;
            remminuts= remminuts%60;
            Remain.setText(String.format("%d : %02d" , remminuts,remseconds));



         // Remain.setText(""+millisUntilFinished);


      }   }

when i give input in minute and seconds and press the fire button the timer will start.But when i exit from my application then the timer is not continue running in the background.I want to continue run the timer when i exit from my application and when i start my application i see the running timer..plz i need help for doing this..
thanks in advance.

  • 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-01T14:35:56+00:00Added an answer on June 1, 2026 at 2:35 pm

    The easiest way to do what you want is to save the current system time when your activity is stopped. When it is resumed again just check how long it passed and update the timer accordingly. To get the current time use

    System.currentTimeMillis();
    

    Have a long member variable that takes the value of current time in onStop. Make sure it’s also saved in onSaveInstanceState and restored in onRestoreInstanceState. Once you are in onResume the timer value must be set to old value + (currentTime – savedTime).

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

Sidebar

Related Questions

I have this code: package com.powergroupbd.timer; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.CountDownTimer;
Here is the code: class Time { public static void printTime (int hour, int
i have a question , i have this timer code in java that when
I have this code: public class Chronom extends Activity { Chronometer mChronometer; ProgressBar progre;
I'm trying to decrypt an encrypted image in Android using this code: public class
When my UI is recreated on orientation change, I use super.onCreate(savedInstanceState) and getLastNonConfigurationInstance() to
Edit: Added code (Exception on line 095, 5th time it's hit.) public DataTable ParseBarcodes(String[]
If I set a timer to execute a code every 3 seconds. If the
Can anyone post a sample code wherein theres a running timer(javascript settimeout) and doing
I want some code to be triggered every second. Usually, I'd create a Timer

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.