The only times I've done this with Notifications, I have used FLAG_ACTIVITY_SINGLE_TOP and FLAG_ACTIVITY_CLEAR_TOP. I assumed FLAG_ACTIVITY_REORDER_TO_FRONT would work as well, but apparently I am mistaken.
On Sat, Nov 26, 2011 at 7:29 AM, KK <dioxide.softw...@gmail.com> wrote: > Thanks for the hints. I'm trying to use theĀ FLAG_ACTIVITY_REORDER_TO_FRONT > flag but the behavior remains as earlier. After the activity starts, I press > "Menu" to go to home and then pull down the "Notification list" click on the > current one (for my demopendingintent activity) and it brings me a new > activity page. I've added exit buttons and logs through which I'm able to > conclude that it starts a new activity rather than bringing the one running > in the background. May be I'm doing something wrong in my code. Please find > below the code snippet I'm using for showing notifications etc. > ---code snippet---- > private void showNotification() { > mNotificationManager = (NotificationManager) > getSystemService(NOTIFICATION_SERVICE); > // //Add current song to notification bar > CharSequence tickerText = "Demo Alert"; > long when = System.currentTimeMillis(); > CharSequence contentTitle = "Now playing"; > CharSequence contentText = "Demo song"; > Intent notificationIntent = new Intent(this, > DemoPendingIntentActivity.class); > notificationIntent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); > PendingIntent pendingIntent = PendingIntent.getActivity( > getApplicationContext(), 0, notificationIntent, 0); > Notification notification = new Notification( > R.drawable.ic_stat_playing, tickerText, when); > notification.setLatestEventInfo(getApplicationContext(), contentTitle, > contentText, pendingIntent); > notification.contentIntent = pendingIntent; > // Make the notification non-clearable > notification.flags = Notification.FLAG_ONGOING_EVENT; > mNotificationManager.notify(notificationId, notification); > } > > and the onCreate() is given below: > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > mButton = (Button) findViewById(R.id.button1); > mButton.setOnClickListener(new OnClickListener() { > @Override > public void onClick(View arg0) { > // TODO Auto-generated method stub > Log.d(TAG, "Shutting down app"); > finish(); > } > }); > showNotification(); > } > --- code snippet---- > Would appreciate if someone can point me whats going wrong here. Many > thanks. > Regards, > KK > > On Sat, Nov 26, 2011 at 5:25 PM, Mark Murphy <mmur...@commonsware.com> > wrote: >> >> Add either FLAG_ACTIVITY_REORDER_TO_FRONT or the combination of >> FLAG_ACTIVITY_SINGLE_TOP and FLAG_ACTIVITY_CLEAR_TOP as flags to your >> Intent. The latter finishes all other activities that might be on your >> back stack; the former simply brings any existing copy of the activity >> back to the foreground. >> >> On Sat, Nov 26, 2011 at 4:51 AM, KK <dioxide.softw...@gmail.com> wrote: >> > hi All, >> > I'm trying to use Notification manager and Pending Intent so that >> > whenever >> > the user clicks the notification the currently running activity's UI is >> > shown. However in the code I'm using, as shown below opens up a new >> > instance >> > of the app instead of leading the user to the currently running one: >> > ---code snippet---- >> > mNotificationManager = (NotificationManager) >> > getSystemService(NOTIFICATION_SERVICE); >> > // //Add current song to notification bar >> > CharSequence tickerText = "Demo Alert"; >> > long when = System.currentTimeMillis(); >> > CharSequence contentTitle = "Now playing"; >> > CharSequence contentText = "Demo song"; >> > PendingIntent pendingIntent = PendingIntent.getActivity( >> > getApplicationContext(), 0, new Intent(this, >> > DemoPendingIntentActivity.class), 0); >> > Notification notification = new Notification( >> > R.drawable.ic_stat_playing, tickerText, when); >> > notification.setLatestEventInfo(getApplicationContext(), contentTitle, >> > contentText, pendingIntent); >> > notification.contentIntent = pendingIntent; >> > // Make the notification non-clearable >> > notification.flags = Notification.FLAG_ONGOING_EVENT; >> > mNotificationManager.notify(notificationId, notification); >> > ---code snippet---- >> > How do I open up the currently running activity instead of opening a new >> > one? Please let me know whats going wrong in the above code. Appreciate >> > your >> > time. >> > Thanks, >> > KK >> > >> > -- >> > 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 >> >> >> >> -- >> Mark Murphy (a Commons Guy) >> http://commonsware.com | http://github.com/commonsguy >> http://commonsware.com/blog | http://twitter.com/commonsguy >> >> Android App Developer Books: http://commonsware.com/books >> >> -- >> 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 > > -- > 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 -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android App Developer Books: http://commonsware.com/books -- 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