0

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.

Community
  • 1
  • 1
Syeda Zunaira
  • 5,191
  • 3
  • 38
  • 70

2 Answers2

3

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

JAAD
  • 12,349
  • 7
  • 36
  • 57
0

in my opinion you should write a service and execute timer in your service which will be executed after every 24 hours and than if you don't want to get date and time from user device you can use google API or any other API for getting time and than decide if app needs to update score or not.

Developine
  • 12,483
  • 8
  • 38
  • 42