I am thinking of making an app that interacts with a Web API.
Requirement:
- Start the bet and Display notification
- Send the bet to the site via POST.
- When the result arrives, update UI with the result.
- If the user hasn't pressed the stop button, back to #2 else stop the bet and remove notification.
- If the app is closed or not the active app, the betting would still continue
- If the notification is clicked, show/start the app
After a lot of research and reading, I thought that the bound foreground service would accomplish this, but I can't find (or maybe I just don't understand) how doing it...
Here are my questions:
If I make a service and put the logic of betting in it, my activity/app would start the service and bind with it..
- How can I tell the service to start betting with the initial bet data from the activity?
- How can the service know when the app closes or is not the active app on screen?
- How can the service update the UI of the app?
I will still search for a possible way to do this. I hope someone can guide me to the right way..
Update
(3) I ended up using LocalBroadcast
to signal the App components from the service of when to update the UI.
(2) By using LocalBroadcast
, I thought that my service should not mind the my App's State.
(1) I used Bound Service
and just call method on the service to pass data and start betting.