Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android notification launches same activity twice

When I click the notification on the status bar it launches an activity but the behavior is strange. If my app is in foreground and I click the notification the notification intent is fired once. If my app is in background then the notification intent is fired twice. If I exit the app (ie all activities have been popped by hitting the back button) then notification intent is fired once. Can anyone explain this behaviour. The code snippet is as follows:

_notification = new Notification(icon_id, "Ticker Text", System.currentTimeMillis());
_showActivityIntent = new Intent();
_showActivityIntent.setAction(MyActivityName);
_showActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK + Intent.FLAG_ACTIVITY_NO_HISTORY);
_showActivityPendingIntent = PendingIntent.getActivity(context, 0, _showActivityIntent, 0);
_notification.setLatestEventInfo(context, "My title", "My text", _showActivityPendingIntent);
_notificationMgr.notify(notificationId, _notification);
like image 693
pankajagarwal Avatar asked Dec 02 '10 10:12

pankajagarwal


1 Answers

_showActivityIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

Try this. it will prevent multiple instances of the same activity. u can put this in the manifest also

like image 116
Varun Avatar answered Sep 28 '22 07:09

Varun