Reputation: 1760
I have an android app that listens for json commands over a socket. I am wondering how I can implement this as a background service. The service would receive the commands and depending on which commands they are, notify the user, or update data within the main program. Some code examples would be great if anyone has them. I've got an example of how to build a background service however it uses timers. I'd like for socket to always be listening.
Upvotes: 1
Views: 9022
Reputation: 4098
In this case you would use a Service which responds to events sent over the socket.
The service should be started by the activity (could also be started on boot if needed).
For code example I would recommend commonwares projects on GitHub. There are many great examples using Services there.
(There is also a service example in an ongoing app I have here.)
Upvotes: 3