Should I use a service for push-notifications?
<p>I'm wondering what is considered best practice for the following case:</p>

<p>I need to keep open a socket in my android client that listens to messages it gets from the server and notifies the user with a toast message.</p>

<p>My first thought went to using a singleton and storing the client I use to communicate with the server there:</p>

<p>This way I can send a message using: </p>

<pre><code>MySingletonHere.getInstance().sendMessage("message");
</code></pre>

<p>A problem I will probably encounter here is doing something in the activity when the socket receives an incoming message.</p>

<p>One way of handling it would be something like this in an Activity:</p>

<pre><code>MySingletonHere.getInstance().setMessageHandler(new MessageHandler() {
    public String handleMessage(String m) {
        Toast.make ...
    }
});
</code></pre>

<p>What I would like to ask is if this is considered a "good" solution because it doesn't feel like one. There probably is an android component that could handle this kind of situation. I don't know much about android development but if I understand correctly a service should be able to perform something like this?</p>

<p>Thanks</p>
