I am working on a messaging app, it sends user notification when he is on a different activtyon my app or is on another app but if the user is on MessagingActivity.java it just updates the chat history and does not send any notifications which is perfectly fine, but the problem arises when the user is on MessagingActivity.java meanwhile an email or something else happen user leaves the MessagingActivity.java open and checks that app if in the meantime a message comes user does not receive any notifications
public void parseRequest(Bundle extras) { if (extras.containsKey("for") && extras.containsKey("recipientID")) { if (Integer.parseInt(extras.getString("recipientID")) == M.getID(this)) { switch (extras.getString("for")) { case "chat": if (isRunning("MessagingActivity")) { Intent intent = new Intent("update_messages_list"); intent.putExtra("data", extras); sendBroadcast(intent); } else { Intent resultIntent = new Intent(this, MessagingActivity.class); resultIntent.putExtra("conversationID", Integer.parseInt(extras.getString("conversationID"))); resultIntent.putExtra("recipientID", Integer.parseInt(extras.getString("ownerID"))); M.showNotification(getApplicationContext(), resultIntent, extras.getString("ownerUsername"), extras.getString("message"), Integer.parseInt(extras.getString("conversationID"))); }