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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:11:05+00:00 2026-05-26T16:11:05+00:00

There are three buttons in class A and class B.CheckIn,Cancel,Complete. Click on one of

  • 0

There are three buttons in class A and class B.CheckIn,Cancel,Complete. Click on one of these buttons leads to corresponding activity in the class B.I am saving the current time in the chronometer in a database with the help of Helper class once in a minute.But I want to continue run the time even I go to the other activities. But I am getting the latest updated time while I was in the Activity.So is there is any solution to run the chronometer even I switch between the activities?? Thanks In advance!!!

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.checkin_timer);
    taskId=getIntent().getIntExtra("taskId", 1);
    status=getIntent().getIntExtra("status", 0);

    String values1[]={Integer.toString(taskId)};
            //Helper class retrieves the time spent with given parametrs
    System.out.println(Helper.getfromUrl(getTimeSpentUrl,values1));
    timeSpent=Long.parseLong(Helper.getfromUrl(getTimeSpentUrl,values1));


    chrono=(Chronometer)findViewById(R.id.chrono);
    btnCancel=(Button)findViewById(R.id.btnCancel);
    btnCheckIn=(Button)findViewById(R.id.btnCheckIn);
    btnComplete=(Button)findViewById(R.id.btnComplete);

    chrono.setText(formatTime(timeSpent));
    System.out.println(timeSpent);

    chrono.setOnChronometerTickListener(new OnChronometerTickListener()
    {

       public void onChronometerTick(Chronometer arg0) {
           // TODO Auto-generated method stub
           time++;
           if(!resume)
                    {
                     currentTime=formatTime(timeSpent+SystemClock.elapsedRealtime()-chrono.getBase());
                     arg0.setText(currentTime);
                     elapsedTime=SystemClock.elapsedRealtime()+timeSpent;
                    }
                    else
                    {
                     currentTime=formatTime(elapsedTime-chrono.getBase());
                     arg0.setText(currentTime);
                     elapsedTime=elapsedTime+1000;
                    }
           if( time== 60 )
           {
               String values2[]={Integer.toString(taskId), Long.toString(elapsedTime-chrono.getBase())};
               String updateTime=Helper.getfromUrl(updateTimeUrl,values2);
               if (!updateTime.equals("success"))
               {
                   Toast.makeText(getApplicationContext(), "Not updated", Toast.LENGTH_SHORT).show();
               }
               time=0;
           }
       }
    });
    if(status==0)
    {
        flag=1;
        this.onClick(btnComplete);
    }
    else if(status==1)
    {

        this.onClick(btnCheckIn);
    }
    else if(status==2)
    {
        flag=1;
        this.onClick(btnCancel);
    }
}
public void onClick(View v) {
  // TODO Auto-generated method stub
  switch(v.getId())
  {   
    case R.id.btnCheckIn:
       btnCheckIn.setEnabled(false);
       btnCancel.setEnabled(true);
       if(!resume)
               {
                chrono.setBase(SystemClock.elapsedRealtime());
                chrono.start();
               }
               else
             {
                 chrono.start();
               }
       String values[]={Integer.toString(taskId),Integer.toString(1)};
       String updateCheckIn=Helper.getfromUrl(updateCheckinUrl, values);
       if (!updateCheckIn.equals("success"))
       {
            Toast.makeText(getApplicationContext(), "Not updated", Toast.LENGTH_SHORT).show(); 
       }
       break;
    case R.id.btnCancel:
       btnCheckIn.setEnabled(true);
       btnCancel.setEnabled(false);
       chrono.stop();


       String values1[]={Integer.toString(taskId),Integer.toString(0)};
       String updateCheckIn1=Helper.getfromUrl(updateCheckinUrl, values1);
       if (!updateCheckIn1.equals("success"))
       {
            Toast.makeText(getApplicationContext(), "Not updated", Toast.LENGTH_SHORT).show();
       }

       if(flag==1)
       {

           chrono.setText(formatTime(timeSpent));
       }
       else
       {
           resume=true;
           chrono.setText(formatTime(elapsedTime-chrono.getBase()));
           String values2[]={Integer.toString(taskId), Long.toString(elapsedTime-chrono.getBase())};
            String updateTime=Helper.getfromUrl(updateTimeUrl,values2);
            if (!updateTime.equals("success"))
            {
                Toast.makeText(getApplicationContext(), "Not updated", Toast.LENGTH_SHORT).show();
            }
       }
       flag=0;
       Intent reasonIn = new Intent(getApplicationContext(), Reason.class);
        startActivity(reasonIn);

       break;
    case R.id.btnComplete:
        btnCheckIn.setEnabled(false);
        btnCancel.setEnabled(false);
        chrono.stop();
        resume=true;

         String values11[]={Integer.toString(taskId),Integer.toString(0)};
         String updateCheckIn11=Helper.getfromUrl(updateCheckinUrl, values11);
         if (!updateCheckIn11.equals("success"))
         {
                Toast.makeText(getApplicationContext(), "Not updated", Toast.LENGTH_SHORT).show();
         }


         String values3[]={Integer.toString(taskId),Integer.toString(1)};
         String updateComplete=Helper.getfromUrl(updateCompleteUrl, values3);
         if (!updateComplete.equals("success"))
         {
                Toast.makeText(getApplicationContext(), "Not updated", Toast.LENGTH_SHORT).show();
         }

         if(flag==1)
           {

               chrono.setText(formatTime(timeSpent));
           }
           else
           {
         chrono.setText(formatTime(elapsedTime-chrono.getBase()));
         String values21[]={Integer.toString(taskId), Long.toString(elapsedTime-chrono.getBase())};
         String updateTime1=Helper.getfromUrl(updateTimeUrl,values21);
          if (!updateTime1.equals("success"))
         {
                Toast.makeText(getApplicationContext(), "Not updated", Toast.LENGTH_SHORT).show();
         }
           }

         Intent completeIn = new Intent(getApplicationContext(), CompletionStatus.class);
         startActivity(completeIn);
         finish();
          break;

    }
}
 public String formatTime(long millis) {
     String output = "00:00:00";
     long seconds = millis / 1000;
     long minutes = seconds / 60;
     long hours = minutes / 60;

     seconds = seconds % 60;
     minutes = minutes % 60;
     hours = hours % 60;

     String secondsD = String.valueOf(seconds);
     String minutesD = String.valueOf(minutes);
     String hoursD = String.valueOf(hours); 

     if (seconds < 10)
       secondsD = "0" + seconds;
     if (minutes < 10)
       minutesD = "0" + minutes;
     if (hours < 10)
       hoursD = "0" + hours;

     output = hoursD + " : " + minutesD + " : " + secondsD;
     return output;
   }

}

  • 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-26T16:11:06+00:00Added an answer on May 26, 2026 at 4:11 pm

    The setBase() is used to set the time that the count-up timer is in reference to.
    . You need to hold on to this value somewhere outside the activity, like in the Application class. Whenever your activity has resumes, you setBase() to this reference time.

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

Sidebar

Related Questions

In this example I create three buttons 'one' 'two' 'three'. When clicked I want
I have one label field and three buttons with the name of red, yellow,
I have three radio buttons with same name and different values.When I click the
In my application I have some link buttons there but when I right click
I have three buttons sending different variables to an activity: Intent i = new
in MXML, there is a Button class which you can instantiate like so: <mx:Button
I have three buttons and need to save some data. I have a idea,
Im planning to create an Alert view with three buttons, my problem is I
I created a simple dialog-based application, and in the default CDialog added three buttons
I have a group of three radio buttons. Depending on which radio button is

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.