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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:11:19+00:00 2026-05-22T03:11:19+00:00

I am using this Android class to implement a countdown: http://developer.android.com/reference/android/os/CountDownTimer.html I have created

  • 0

I am using this Android class to implement a countdown: http://developer.android.com/reference/android/os/CountDownTimer.html

I have created an own class My Count:

public class MyCount extends CountDownTimer{

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

@Override
public void onFinish() {
tv_test.setText("");
}

@Override
public void onTick(long millisUntilFinished) {
tv_test.setText("d"+ (millisUntilFinished/(3600000*24))+ " h: "+  (millisUntilFinished/3600000)%24  +" m: " +  (millisUntilFinished/60000) % 60 + " sec: "+   (millisUntilFinished/1000) % 60);

}

}

in onStart() of my activity I have this code:

MyCount counter = new MyCount(time, 1000);
        counter.start();

The problem is now: If I navigate to next activity and come back, the countdowntimer is started again and there run two countdowns.

I can not put it in onCreate() because the time variable can be changed by the user. He changes it on an other activity

  • 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-22T03:11:20+00:00Added an answer on May 22, 2026 at 3:11 am

    try to add a boolean
    example :

    booelan counterIsLaunched = false;
    boolean timeChanged = false;
    

    and in your implementation of the counter add this :

    @Override
    public void onFinish() { tv_test.setText("");
    counterIsLaunched = false;
    if(timeChanged) start();
    }
    @Override
    public void onTick(long millisUntilFinished) {
    tv_test.setText("d"+ (millisUntilFinished/(3600000*24))+ " h: "+  (millisUntilFinished/3600000)%24  +" m: " +  (millisUntilFinished/60000) % 60 + " sec: "+   (millisUntilFinished/1000) % 60);
    counterIsLaunched = true;
    if(timeChanged) start();
    }
    

    and in your onStart() try to test the variable

    if(counter.getCounterIsLaunched() == false ) {
    counter.start();
    }
    

    and when you changed the timer , do something like this :

    counter.getTimeChanged() = true;
    

    hope it helps man 🙂

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

Sidebar

Related Questions

i have created a coverflow using the code given by http://android.jmsliu.com/138/android-infinite-loop-gallery.html . And it
I'm learning about using Custom Views from the following: http://developer.android.com/guide/topics/ui/custom-components.html#modifying The description says: Class
I'm starting Android Market via my app to search for similar products using this
This is pretty simple: I'm using NetBeans on Linux with Android emulator 1.6. I
I'm using a ListView that is setup like this: <ListView android:id=@android:id/list android:layout_width=fill_parent android:layout_height=fill_parent android:longClickable=false
export PATH=${/home/mohit/}:<android-sdk-linux_86>/tools this is what i am using.. error:-- bash: PATH=${/home/mohit/}:: bad substitution this
Using this file as source, I have a situation where I need to retrieve
Using this answer , I created a sample localized app. My question is, is
Using this: Can I use Facebook's fb:friend-selector in an iframe? I created a multi-friend
I am using the following to mock my location in Android. public class GPSwork

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.