I have an activity MyActivity and a background service. When MyActivity is not in the foreground, I show a notification icon in the system tray. When the user selects the icon, I want MyActivity to be displayed instead of creating a new instance of MyActivity. However, this does not seem to work even though I set Intent.FLAG_ACTIVITY_REORDER_TO_FRONT - a new instance gets created if MyActivity was not on top of my task's stack.
I have also set launchMode="singleTop" on my MyActivity. This works in the sense that if MyActivity is not visible but is at the top of my task's stack, the existing instance will be brought to the foreground when the user clicks on the notification icon - a new instance will not get created. Without "singleTop", a new instance was being created. However, I also want this to work if MyActivity is not at the top of my task's stack. Any idea how to make that work? Intent notificationIntent = new Intent(MyService.this, MyActivity.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); PendingIntent pendingIntent = PendingIntent.getActivity( MyService.this, 0, notificationIntent, 0); Notification notification = new Notification(); notification.icon = R.drawable.my_notification_icon; notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.flags |= Notification.FLAG_NO_CLEAR; notification.setLatestEventInfo(MyService.this.getApplicationContext(), getResources().getString(R.string.my_ongoing_notify_title), getResources().getString(R.string.my_ongoing_notify_text), pendingIntent); startForeground(Constants.MY_ONGOING_NOTIFICATION, notification); -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en