0

In my application I do a ranking of the points of a user. However, I do the calculation of my ranking just every 24 hours. My problem is that I do not know where I should put the code of the calculation without disturbing the user.

Is it not possible to have a code in the "background" who will be called every 24h? Because at the moment, the code for the calculation is called when the first user uses my app after 24h, but then the user has to wait some minutes until the calculation is over. My data of every user is saved with Firebase.

Thanks in advance!

Joan P.
  • 2,368
  • 6
  • 30
  • 63
Jan
  • 117
  • 2
  • 8

2 Answers2

1

Edit April 22, 2019:

Recently, Google Cloud released Cloud Scheduler, which allows you to schedule HTTP requests or Cloud Pub/Sub messages to functions that you deploy.

This new service works also very well with Firebase and for that I recommend you read an excellent article writen by Doug Stevenson on the Firebase blog named Scheduling Cloud Functions for Firebase (cron).


Is it not possible to have a code in the "background" who will be called every 24h?

Yes, it is possible. In this case, you should write a function in Cloud Functions for Firebase and call it whenever you needed. If you want to be triggred every 24 hours, use the follwing service:

This means that you can do that particular calculation even if the user has the app closed. For a code example, please see Frank van Puffelen's answer from the following post:

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
1

For your case I'd recommend using default Android tools for scheduling jobs. You can try using a new WorkManager or just a JobScheduler. Also you can try digging into this article to get more information.

Stanislav Shamilov
  • 1,746
  • 11
  • 20