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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:55:54+00:00 2026-06-13T05:55:54+00:00

I am using <Chronometer android:layout_width=wrap_content android:layout_height=wrap_content android:id=@+id/chrono android:visibility=gone /> in my one activity now

  • 0

I am using

<Chronometer android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/chrono"
        android:visibility="gone" />

in my one activity now my question is can I make it global for all of my activities so that I can show its value to every activity in my android app?

If yes then how to do this please give example because I am new in android??

Here is my timer code

Chronometer stopWatch;

        stopWatch.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener(){
            @Override
            public void onChronometerTick(Chronometer arg0) {
                countUp = (SystemClock.elapsedRealtime() - arg0.getBase()) / 1000;
                long min = countUp / 60;
                long sec = countUp % 60;
                String minStr = "";
                String secStr="";

                if(min < 10)
                {
                    minStr = "0"+min;
                }
                else
                {
                    minStr = ""+min;
                }
                if(sec<10)
                {
                    secStr = "0"+sec;
                }
                else
                {
                    secStr = ""+sec;
                }

                // String asText = (countUp / 60) + ":" + (countUp % 60);
                String asText = minStr + ":" + secStr;
                textGoesHere.setText(asText);
            }
        });
        stopWatch.start();
  • 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-13T05:55:55+00:00Added an answer on June 13, 2026 at 5:55 am

    Here is an idea. Create a separate layout for your Chronometer and <include /> it in all the layouts that require a Chronometer.

    Now you can either use a Singleton pattern or SharedPreferences to store the attributes such as start time, current state (Paused, Running, Stopped, Reset) of your timer. Whenever you start a new activity get the state of the timer and show it on your Timer.

    For instance if the current state is running then you may have to kick start a thread to update the timer or if the timer is stopped just get the start time and stop time from your SharedPreference or your Singleton class and show it on the timer.

    For instance, consider the following scenario. For simplicity let’s have 2 Activities, ActivityA and ActivityB.

    Now here are some of the states for your timer, yours could be different.

    1. Ready (00:00 – Your timer is ready to run)
    2. Running (Timer is running)
    3. Paused (Timer is paused and can be resumed)
    4. Stopped (You have stopped the timer and it displays the elapsed time and the next possible state would be 1 i.e, ready.)

    You would need several other parameters such as,

    1. Timer start time (System.currentTimeInMillis() minus this time gets you elapsed)
    2. Timer stop time (Used to calculate timer paused and stopped time)

    Let’s consider this case. You are starting a timer from ActivityA and want to retain the state on ActivityB. Here are the set of things you might want to do.

    When you start your timer by any event – say click of a button, you have to save the start time in your SharedPreference.

    Now you want to navigate to ActivityB, then you have to save the timer state to your SharedPreference in the onStop() method of your ActivityA.

    Now after you start ActivityB, in the onResume() method get the start time from the SharedPreference, the System.currentTimeInMillis() minus the start time will give you the elapsed time. Next, you have to get the timer state from your SharedPreference.

    If the state is running, then you have to start a thread to update the timer. If the timer is stopped, then it’s enough to show the time elapsed on your timer.

    This is the outline of the solution. You can learn about SharedPreferences from here.

    Also, you need to be familiar with the Activity lifecycle, which you can learn from here.

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

Sidebar

Related Questions

Using Android TelephonyManager an application can obtain the state of data activity over the
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using jQuery, one can easily find out whether a particular element is visible using
Using VS2008, C#, .Net 2 and Winforms how can I make a regular Button
Using Location.getBearing(); I seem to get randomly changing bearings. Aka, I can turn the
There are few built in ways to invoke a timer using the Android stack,
Using mercurial, I've run into an odd problem where a line from one committer
Using Delphi 2010. I am looking for (possibly) a function or procedure which can
What I want is to measure time with milliseconds, but using Chronometer has the
Using Tsql, how can I find out when MS SQL server was installed?

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.