ummah Host
ummah Host

Reputation: 69

Notifications not show up

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")));
                    }

Upvotes: 0

Views: 42

Answers (2)

pat_brat
pat_brat

Reputation: 484

I am by no means an expert, but you could just set a boolean variable by overriding the Activity's onPause() and onResume() events.

Simply set msgActivityActive to true in onResume(), false in onPause(), and change your call to:

if (isRunning("MessagingActivity") && msgActivityActive)

Upvotes: 0

Vindhya Pratap Singh
Vindhya Pratap Singh

Reputation: 556

Let me know how you are checking that your MessageActivity is Running i.e. functioning of isRunning("MessagingActivity") method. If you are setting any global boolean variable for checking this and making isRunning value false in onDestroy() method of that activity then, according to life cycle of Activity it is not called until your activity is finished i.e. in your case user just switching from MessageActivity to Mail .

Upvotes: 1

Related Questions