Android Question permanent clock in the background

Justcooldev

Member
Licensed User
Hello, I am currently working on a mobile application that allows you to point NFC tags at different places. The goal is to retrieve the date and time of the NFC score and send it back to a server.
We cannot use server time because sometimes users will be offline.

We would like :

1) install a clock that will run permanently in the application
2) this clock will be updated when there is network
3) put our application in the background during the day so as not to lose the NFC check-in times

How to do it ? I'm a new B4X user and it's not easy for me.
Thank you for your help.
 

agraham

Expert
Licensed User
Longtime User
1) The device will have a clock that gives you date and time when you request it.
2) When you ask the server for its time save the difference, if any, between that and device time so you can synchronise their clocks.
3) Sorry, no idea. I've never really understood background services in Android.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
3) put our application in the background during the day so as not to lose the NFC check-in times
To start with the consequence of this choice, a program running in the background basically consumes power and processor time. In addition, you have no guarantee that the OS, or the user, or a dead battery will kill the program. So it's a choice that can be improved.

I recommend looking at the [B4X] KVS - KeyValueStore library solution. Using B4X KVS is similar to using a Map. You initialize it once and then you can place or retrieve items using the Put, Get or GetDefault methods when opening the program and entering or reading the login and logout times. The only risk that remains is that the phone battery is empty during use, but what is the chance (ok :eek: that happens to all of us sometimes, but you see that in contrast to those underwater activities of your OS that kill the program.) Another additional advantage is that you can also store information and if necessary you can also send or download the database.
 
Upvote 0
Top