2

I have a problem with Pending Intent in my app.

I have an activity, a notification with pending intent to launch that activity.

When my app is NOT displayed ( not foreground), I scroll the notification bar down and launch my app from my notification. It works fine.

But when my app is foreground, I want the activity is not launched again if user press on my notification because It has been displayed already.

I don't want my pending intent launch the activity in this case. How can I do or please give me some key word for searching?

Eonasdan
  • 7,563
  • 8
  • 55
  • 82
Paul
  • 950
  • 2
  • 12
  • 28
  • 3
    you could cancel the notification whenever your application is visible. – Steelight Oct 29 '12 at 13:48
  • How can I do that. My notification is in a Service? – Paul Oct 29 '12 at 13:53
  • 1
    In your launching `Activity` try `android:launchMode` with `singleInstance` – Mohsin Naeem Oct 29 '12 at 13:54
  • Oh, I use singleTask and It works fine, singleintance just solves my problem but make more bad things. thank you so much for suggesting. – Paul Oct 29 '12 at 14:05
  • I think that not displaying the notification when the user is in the app may be the best option. It depends on your usecase of course. I display a notification when my music app is playing a track, but as soon as the user enters the app, I use notification.cancel to hide it (and I recreate it in onPause) – Teovald Oct 29 '12 at 14:11
  • If you have solved your problem by creating your activity singleInstance/singleTask then please avoid using it, better is to clear the notification programmatically. – MKJParekh Oct 29 '12 at 14:54
  • I'm using Foreground Service with Pending Intent. – Paul Oct 29 '12 at 15:18
  • Hello, I have tried a method that CommonWare tell me and It worked. Just add flag FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_SINGLE_TOP to intent that PendingIntent uses. – Paul Oct 29 '12 at 15:54
  • Please see my answer to this question: http://stackoverflow.com/questions/6575730/notification-to-restore-a-task-rather-than-a-specific-activity – David Wasser Jun 04 '13 at 21:16

0 Answers0