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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:19:54+00:00 2026-06-15T12:19:54+00:00

I have Activities A,B,C,D… I create a countdowntimer in activity A….I want to call

  • 0

I have Activities A,B,C,D… I create a countdowntimer in activity A….I want to call its methods in activities B,C,D …. how do i that…I tried making the timer variable static but it has some problems and doesn’t function properly…Also its not a good programming practice..So is there any other way to do this??

public class CountTime extends Activity {

    static MyCount count;
    Button clickBtn;
    TextView tv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.customanim); // 5000 is
                                                                // the
                                                                // starting
                                                                // number
                                                                // (in
                                                                // milliseconds)
        // 1000 is the number to count down each time (in milliseconds)
        count = new MyCount(5000, 1000);
        count.start();
        tv = (TextView) findViewById(com.example.sample.R.id.textView1);

        clickBtn = (Button) findViewById(R.id.button1);
        clickBtn.setText("Click me");
        clickBtn.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                Intent my = new Intent(getApplicationContext(),
                        MainActivity.class);
            //my.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(my);
            }
        });
    }

    @Override
    public void onUserInteraction() {
        // TODO Auto-generated method stub
        super.onUserInteraction();
        //count.start();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        count.cancel();
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        count.start();
    }

    // countdowntimer is an abstract class, so extend it and fill in methods
    public class MyCount extends CountDownTimer {
        public MyCount(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onFinish() {
            tv.setText("done!");
            Toast.makeText(getApplicationContext(), "Finsihed", Toast.LENGTH_LONG).show();
        }

        @Override
        public void onTick(long millisUntilFinished) {
            tv.setText("Left: " + millisUntilFinished / 1000);
        }
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
    }
}
  • 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-15T12:19:55+00:00Added an answer on June 15, 2026 at 12:19 pm

    probably the best approach for that will be creating a Singleton class with your Timer.

    If you don’t know what the Singleton is you can find it in below sources:
    http://www.javaworld.com/javaworld/jw-04-2003/jw-0425-designpatterns.html
    http://en.wikipedia.org/wiki/Singleton_pattern

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

Sidebar

Related Questions

I have three activities that I can call A, B and C. I want
I have 40 activities that do not depend on each other. I want to
I have 2 activities. The first activity is an activity that parses JSON data
I have 2 activities. MyMain MySecond I call MySecond activity in MyMain activity. And
I have many activities in my application(eg A->B->C->D)...i have a countdowntimer that i am
I have two Activities along with one Application class, and whenever I call my
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
i have to activities AnswerQuestion.java and SendAnswerToServer.java , and i want to send data
I have five activities/screens that I would like to be able to swipe between,

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.