Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
            }
like image 475
tyczj Avatar asked Dec 06 '25 10:12

tyczj


1 Answers

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

like image 70
nandeesh Avatar answered Dec 09 '25 20:12

nandeesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!