Search code examples
androidscheduled-tasksandroid-alarms

Make a server on call on every first of the month


I am building a game and now I have to send user scores on every first of the month to the server .

I have multiple options like

  • Timer
  • ScheduledThreadPoolExecutor
  • Service
  • BroadcastReciever with AlarmManager.

but not sure which one to use. for the following reasons:

I don't think Alarm or Timer will be the best as it doesn't make sense to have an alarm after every month as user may can install the app at any date.

besides that I can't even check the date from user device as what if the user has wrong time set on device?

And what if the user doesn't have the internet connection available at first of the month or what if he didn't launch the app on the first.

I know we can use service for this problem but again is it feasible to always run the service in background which only requires once a month?

I checked other SO post too like this Scheduling recurring task in Android

but its not same as my case as I only have to make the calls once in a month. Thanks.


Solution

  • use

    AlarmManager is your best bet.
    

    Your Issue:-

    while scheduling an alarm check the current date and schedule the alarm accodingly EX:- if today is 17th schedule alarm after 14 day.

    Regarding getting the current date put the current date on server and get it from there