Communication between Service and any Activity
<p>I have a code for send message from service to activity. But I only send message to the activity that create the service.
If I change the activity and service still active i need recive the messages in new activity. how?</p>

<p>I use this code:</p>

<p><strong>Activity</strong></p>

<pre><code>public static Handler messageHandler = new MessageHandler();

...


    public static class MessageHandler extends Handler {
        @Override
        public void handleMessage(Message message) {
            int state = message.arg1;
            switch (state) {
            case HIDE:
                progressBar.setVisibility(View.GONE);
                break;
            case SHOW:
                progressBar.setVisibility(View.VISIBLE);
                break;
            }
        }
    }
</code></pre>

<p>Then, I create service passing the handler.</p>

<pre><code>Intent startService = new Intent(context, SERVICE.class)
startService.putExtra("MESSENGER", new Messenger(messageHandler));
context.startService(startService);
</code></pre>

<p>When change the activity I stop receiving messages. I can create a messageHandler class in any activity? thats work? Thanks!</p>