Stopwatch running in background even app close using tiny db

dear all
i need help in my app i need start stopwatch to keep count the time when i click the in button and even i close the app time keep running until i click out

Please search on Community before create a new topic

1 Like

thanks for advice i do that but i couldn’t reach what can help me so that i create this topic :face_with_hand_over_mouth:

store the start time in TinyDB so you always will be able to calculate the duration even if the app was closed temporarily
Taifun

2 Likes

thanks for your fast respond with me kindly if you please support me with some blocks i will send the aia in attachbackground.aia (3.5 MB)

if you are not able to understand, what I was saying, then please do some tutorials to learn the basics
also please try something yourself and if you got stuck, then post a screenshot of your relevant blocks

Taifun


A very good way to learn App Inventor or Kodular is to read the free Inventor’s Manual here in the AI2 free online eBook App Inventor 2 Book: Create Your Own Android Apps … the links are at the bottom of the Web page. The book ‘teaches’ users how to program with AI2 blocks.
There is a free programming course here Course In A Box and the aia files for the projects in the book are here: App Inventor 2 Book: Create Your Own Android Apps
How to do a lot of basic things with App Inventor are described here: How do you...? .

Also do the tutorials Tutorials for MIT App Inventor to learn the basics of App Inventor, then try something and follow the Top 5 Tips: How to learn App Inventor

3 Likes

Thanks Taifun
i try to learn as i can so I’m apologize if my questions been as stupid or something i will check what you send me and thanks again for your help and support

There’s no stupid questions, some people know some things that others don’t. That’s all.
But you need to learn how to do it yourself. Asking for the blocks is not a good idea because you are not learning, just copying what others do and you will never understand what those blocks do, unless you come up with the solution by yourself.
For @Taifun’s solution, you might want to check the Clock component, save the current time in milliseconds in a TinyDB tag when the app is closed, or suspended.
Then when the app is opened (Screen1.Initialize), check the time saved in TinyDB and compare it with the current time. That will let you know how much time passed since the stopwatch was started.

1 Like

Some time ago I added some statistics to an app (created with AI2), maybe some blocks will help:

3 Likes

thanks for your reply i appreciate all support, its greet community and im so happy being here

2 Likes

:pensive:


i try as you say but i get problem

The duration block accepts INSTANTS blocks, not miliseconds.

Use this block to convert milliseconds to instant

image


sorry for that i need help

Is that a comma there? It should be only the milliseconds number.

i try this but still not working

use Do it to debug your blocks
see also tip 4 here App Inventor: How to Learn | Pura Vida Apps
Taifun

What is not working?
Your blocks look fine, should work, so try this:

duration_test.aia (2.8 KB)

i get the solutiontime.aia (14.9 KB) as attached

No, that won’t work:

1 Like