Help with Time duration

Hi guys I'm currently having an issue trying to get the duration between two times, I've looked on here and used one of the examples to try solve the problem but I keep getting the error as shown below. I'm not sure what I can do to resolve it. Any help would be greatly appreciated.




To get durations it would be best to work with instants and the clock duration blocks, or to work with millis.

The problem I've got is the app would need to stay active for a 8 hour shift to deal with an instant. Can you think of a work around that could fit to my use?

You then either need to:

  1. capture the time when ever the app goes to sleep / into background, and use this when the app is active again to set the correct timings

or

  1. Use a background extension

Thank you, is there any free background extensions available?

What do you mean by "background"

  1. The app is in the background (after pressing the device Home button
  2. or it is in idle (sleep) mode (i.e. the app is not visible)
  3. or the app was closed?

In the case of the first two, you must use a Foreground service to keep the timer alive (i.e. in Doze mode, Android ≥ 6).

In the third and last case, you need a background extension that also has a foreground service implemented.

What exactly is the purpose (goal) of your app?

Thank you.

Sorry I meant option 3. I'm trying to create a clocking in system but kept getting the above error as per my picture. I wasn't sure what the problem was.. TIMAI2 was kindly suggesting the above. The issue I have is I'm not that all familiar with the solution.

Hello Samuel

In future, do not take photographs of your screen - instead use App Inventor.
Right-mouse in the Blocks work area and select "Download Blocks as image"
download blocks

So what does your App actually do Samuel? What is it for? I get the impression it is for logging someones work hours? Log in - Log off?

It is important that we understand the goal of your Project because it's possible you are asking the wrong questions to get there!

I could well be doing ChrisWard. As mentioned above "I'm trying to create a clocking in system" to log people's shifts and get the duration of the shift from when first clocked in till end of that shift. I appreciate all the help everyone has so far offered. Thank you guys

Is that just for the individual's own record or for the company? If the latter, the data should be saved to the Cloud.

Rather than have the App running for 8 hours (or more), which will not be popular with your Users, Wouldn't it be better for the User to save the Start time and Finish time and when the Finish time is saved, the data is sent to the cloud?

It's for a company, I've saved the start shift to clouddb but get the error when shift ends called. I'm not sure what else to do..

So how about this:

After the User has Saved the Start Time (Current time is presented) and entered duration (default to 8 hours):

  1. The App saves the Start Time to the cloud as Hours:Minutes
  2. The App sets the Device (System Alarm) to run when the Finish time is reached
  3. The User can Close the App
  4. When the Device Alarm alerts, it notifies the User to run the App
  5. The App sends Start Time and Finish Time to the Cloud

You can set the Device alarm with Taifun's Alarm Extension (free version)

I'm not sure how's that different from what I've already got in place? I save the start time to clouddb and when the user finishes his/her shift it calls clock1 now,saves it to a global variable and should workout the duration from that..

Post the aia or better a small (simple) test aia.

Please find attached my blocks if that helps

thank you all for your help, I have worked out the issue myself slight_smile:

Well, your code resembles Swiss cheese........ but good to hear you have fixed things by yourself.