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?
I use this code:
Activity
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;
}
}
}
Then, I create service passing the handler.
Intent startService = new Intent(context, SERVICE.class)
startService.putExtra("MESSENGER", new Messenger(messageHandler));
context.startService(startService);
When change the activity I stop receiving messages. I can create a messageHandler class in any activity? thats work? Thanks!