Take the 2-minute tour ×

So I am currently showing a notification. When the user clicks this noticiation, the application is started. The notification persists, to indicate that the service is running in the background.

Intent notificationIntent = new Intent(context, LaunchActivity.class);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(1, notification);

However, I have detected a case where a bug appears. If the user starts the application through clicking the normal icon, and while the activity is running clicks the notification, then a new activity is started without the earlier one exiting, the later being on top of the earlier. And that is not all: Further clicks on the notification will create additional activities and place them on top of those already running. How can I prevent this? Is there a nice check to do to see if a certain activity is currently being shown or is loaded?

share|improve this question
add comment

3 Answers

up vote 22 down vote accepted

That's the way it's supposed to be by default. You probably need to specify android:launchMode="singleTop" if you want to have a single instance only.
There are 4 launch modes, more info here: http://developer.android.com/intl/de/guide/topics/manifest/activity-element.html

share|improve this answer
Setting it to "singleTask" solved my problem. Thanks for helping me out! –  pgsandstrom Feb 25 '10 at 9:05
add comment

When using the lanchMode="singleTask", if an intent of your activity already exists, Android does not re-create the Activity but launch it with the onNewIntent() method.

As documented by Android :


Android documentation for activity mode

share|improve this answer
add comment

As the two answers above have mentioned, you'll want to set the application's launch mode which is defined in the activity's definition in the manifest:


Additionally, you may want to note, that despite FLAG_ACTIVITY_SINGLE_TOP being a valid Intent flag, there are no equivalent intent flags for singleTask or singleInstance.

See the launchMode section for more details on the different launch mode options: http://developer.android.com/guide/topics/manifest/activity-element.html#lmode

share|improve this answer
add comment

Your Answer


