My app has a chat screen to send and receive messages. Whenever a message is received a push notification comes in and shows the latest received message. This all works fine.
But when I get my push notification I would like the chat screen to refresh itself. I guess this would require knowing if the chat screen is currently visible or not. How can I do this from the onReceive()
method of my BroadcastReceiver
?
Here's a little pseudo code (in my BroadcastReceiver
subclass):
public void onReceive(Context context, Intent intent)
{
if(currentlyVisibleActivity.getClass() == chatScreenActivity.class())
{
((chatScreenActivity)currentlyVisibleActivity).getMessages();
}
}
I would like to know how to get the currentlyVisibleActvity and make it call getMessages()
if it's a chatScreenActivity.