How to implement trigger based on time in mobile? - android

I am trying to develope android mobile app and I have bids with limited time and that time decrease if the user click on bid button for example:
if we have bid with 5 hours and if on click = 1 hour so if five users clicked the bid button then the bid should close.
The problem appear if no one bid on bid so I need to colse it after 5 hours.
So far I have sql server 2016 cloud database with two columns bid and the remaining time and the remaining time decrease by each click. but if noclick I have to check every second using cron job to check the remaining time and close once it reach zero.
I don't think the cron job is the optimal solution I tried to check the trigger time base but didn't find any in sql server.
Could you tell me the best technique to solve the problem may be a new technique to solve it from mobile prospective or sql server view?

Related

How to track online and offline app usage duration on Firebase?

I already have a service that sends how much time by minutes a user was online or offline every 15 mins and only after the state has changed from the previous one (online to offline or vice versa). So, basically, I can see the minutes count as a value when selecting a parameter, for example, ONLINE_TIME (in screenshot called TIME), and see events in the last 30 mins with values of how much time the user was online by minutes.
My main goal is to see in Firebase, how much percent time of the day users was online and offline. Any ideas on how could I achieve this? Thanks.

Displaying time exceeded (Timer) on Android Studio using Firebase?

My question might be bit confusing, but what I basically want to do is,
I want to display the time exceeded for each item in the list when the start button on each item is clicked.
For example, suppose I have a listView of items that has a time and a button
TIME START
TIME START
TIME START
When I click the start button, the TIME textView should start a timer that increments every 1 minute and stops when it reaches a specific minute).
Since I am using the Firebase realtime database as my DB, I was thinking of incrementing 1 to the Time data every 1 minute.
What is a good approach of doing this?
You can update a value in Firebase Realtime Database either on client side or either on server side by using Cloud Functions for Firebase.
You can write a function that updates that particular value every 10 minutes. The benefit of using Cloud Functions rather then the first option is that will still work even if the application is offline. This is the best practice.

Accurate time without sim and without internet

I have an app which is used for collection all day users collecting amount normally offline and then in the evening they uploaded amount online. Sometimes there device date and time is inaccurate so they uploaded wrong data.
At the time of collection my app is getting date and time from the device. Is there any way that app always store accurate date and time without Sim and without the Internet.
You can create a Sqlite Table in application cache when user switch on data,you
can save current server time in that Table and in offline mode you can compare server time with current time. this is the nearest approach to get accurate time
Well, before searching for an app to do this. As a human how can you tell if the date/time is correct without internet?
A possible solution would be a service which counts seconds from the last time the device was connected to the internet (which means it had a correct date/time at that moment) then when you want to add the new amount you can add the seconds to the last time and store this value.
Edit
You will 2 things to achieve this:
BackgroundService
Counter which you can achieve in many ways, I would go the easy way. check this: how-to-measure-elapsed-time
Or you can have an AlarmManager to do this.
One more thing You need to be careful if the device goes off or for some reason, something stopped the service. All of these are user issues and you need to decide how much you want to handle stuff for the user.
You can fix user mistakes by pushing to a SqlLite database every 10~15, but this won't fix if the device went off for hours and then started again at a wrong time - I don't think there is a possible solution for this-.

How to make my application wait for a specific time interval if the system is overloaded

I am working on a restaurant project which sends the order of the customer from a android tablet to the kitchen, I want my application to wait for a specific time before sending the order to the kitchen if the server already containing more than 10 orders. In short I want my application to read the number of orders and wait, Kindly guide me if it is possible.
To wait big intervals of time I recommend you to use AlarmManager
http://developer.android.com/reference/android/app/AlarmManager.html
The pseudocode for the problem would be something like this:
1 Request to check number of orders
2a If <= 10, send the order
2b If not create an Alarma to wait X minutes and return to 1
Anyway, this has a lot of problems like what happends if a lot of tablet are waiting to send the order, how can the tablets sort the orders? One order can be waiting infinite time because other orders are scheluded before always....
In my opinion you should save all the orders in the server and manage the orders from there. That is the best and simple solution. Then in your server you can always show to the kitchen only 10 orders and manage what order show when one is finished and given to the client. If not, you will need a very complex system to comunicate between the tablets, but for me has no sense the cost of do that

Health/Energy consumption and restoration

I am new to developing games and apps in android, as much a noob as i am i was wondering how i could implement a health/energy bar.
Such as candy crush, so when you die you lose 1 health and a timer starts for aprox 15 minutes and when that timer ends you recive that 1 health back.
If you lose 5 times you run out of health and cannot play until you have restored atleast 1 health.
I was thinking of tracking it like a score system, so when you press the play button 1 health is removed and you start a timer, not sure how i would implement this thou.
Any help is much appriciated!
Theoretical attempt, implementation up to you.
I would have a SQLite DB where you store your lifes. Initially let's say 5. When a users fails it is substracted. Now this is where you would add or change an entry in a DB or in SharedPrefs.
Your DB would look like:
lifes=>4
restoreTime=>27.02.2014 14:34:22 (that is the time when a new life will be added)
In you game loop just periodically check for if you are already behind that time. If so add lifes by calculating the difference of time divided by the length of your "regen" time and
if(newLifes == 5) delete restore time or set it to infinity or a date in 9999 years or so (so it wont increment in the next gameloop check).
else update restore time to the next time it will add lifes.
You see: Making games is not that trivial ...

Categories

Resources