I need a node in my database to increment by 1 every minute for my App (to inform users how many minutes have passed in the game). I obviously need a listener but I'm struggling with which clock to use. Should I use the Android Clock? But that will have lifecycle issues. Seems best to use a clock not on the client side. Maybe use Firebase functions? Thanks.
Asked
Active
Viewed 260 times
1
-
http://cron-job.org/ – Doug Stevenson Jun 06 '18 at 14:02
-
thanks I came across that site. But I'm not sure how it'll help me constantly updating firebase node by one minute. – flutter Jun 06 '18 at 14:20
-
Use it to ping a Cloud Function to do the work you want. – Doug Stevenson Jun 06 '18 at 14:24
-
thanks, to be clear.. I need to ping cloud functions(with cron jobs) every minute to update my FB database to increment every minute? – flutter Jun 06 '18 at 14:28
-
1There is no auto-increment-every-minute operation built into the Firebase Database. If you need that functionality, you will have to either do that from the client-side apps (as Mahesh answered) or do it from a server-side environment such as Cloud Functions. Since Cloud Functions only run in response to triggers and don't have a built-in trigger for time yet, you can use a service like cron-job.org to emulate that. See https://stackoverflow.com/questions/42790735/cloud-functions-for-firebase-trigger-on-time – Frank van Puffelen Jun 06 '18 at 14:33
-
Use an online clock/ time server such as [this one](https://tech.instacart.com/offline-first-introducing-truetime-for-swift-and-android-15e5d968df96). In your FirebaseDB, either set the start time or end time in seconds for whatever event you are waiting on (in GMT+0) and then check the online clock (also GMT+0) to check relative time to the timestamp. This will reduce your load on your Firebase connections (which cost money). Use CloudFunctions to generate the timestamps server side and let the client query the timestamp (read-only). – James Poag Jun 06 '18 at 15:10
1 Answers
1
Use timer task for update firebase node every one minute(Use Below code to update everyminute):
final Handler handler = new Handler();
Timer timer = new Timer();
TimerTask doAsynchronousTask = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
@SuppressWarnings("unchecked")
public void run() {
try {
"Your function call "
}
catch (Exception e) {
// TODO Auto-generated catch block
}
}
});
}
};
timer.schedule(doAsynchronousTask, 0, "Timer value");

Mahesh Keshvala
- 1,349
- 12
- 19
-
-
1What if there are no connections/clients? Then the task will not execute. What if there are 100 clients - they would all be triggering an update. – Jay Jun 06 '18 at 15:43