tyczj
tyczj

Reputation: 73741

Updating an intent that starts an activity

I have an intent that starts an activity that shows an alert dialog when a new message comes in from GCM (Google Cloud Messenger). The Dialog shows the number of unread messages but if a new message comes in after one was already displayed and you have not viewed the previous one the dialog should update the unread count to reflect the number of new/unread messages.

However the intent does not update the dialog if the activity with the dialog is active so how can I update it since I cant call dismiss on the dialog?

the intent if there is a new message

if((incMsgs + dlMsgs) > 0 && !mMsgType.equals("Reg")){
                edit.putBoolean(Preferences.NEW_ALERT, true).commit();
                priorityMsgs = true;
                Intent i = new Intent(this,NotificationDialog.class);
                i.putExtra("incidents", incMsgs);
                i.putExtra("dlMessages", dlMsgs);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(i);
            }

Upvotes: 3

Views: 4748

Answers (2)

Rodrigo Xavier
Rodrigo Xavier

Reputation: 222

I've solved my issue by adding this on my intent:

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

Maybe this can help you too.

Upvotes: 1

nandeesh
nandeesh

Reputation: 24820

You will have to override OnNewIntent of the activity. And in this update the Ui elements. For this to work your activity launchMode needs to be singleTop

Upvotes: 4

Related Questions