The server stores the schedule of matches. I need the application to send a GET request to the server every time at a certain interval and take a fresh schedule, even if the application is not running (the user will be notified if his team plays), but the Internet is turned on. The server returns the schedule in json format. How to implement it?
2 answers
You need to act like this:
- Subscribe to the launch of the device . Catching this event is necessary
BroadcastReceiverth, registered in the manifest and subscribed to the eventandroid.permission.RECEIVE_BOOT_COMPLETED. You also need the appropriate permission in the manifest. - At the time of launching the device, you need to use the
AlarmManagerto create your own periodically sent content , which will call the 2ndBroadcastReceiverevery n-minute - Actions from the second point should also be done when the application is started. Otherwise, your intents will not be registered in the system until you restart the device.
- In the second
BroadcastReceiver, launched when sending out your own intents, you need to run anIntentServicein which you make a request to the server and output, if necessary, a notification
|
In my opinion, for such a case, you do not need to send a request at a certain time interval, but send a notification from the server via Firebase cloud message. This is quite simple to set up.
|