Reputation: 21
I have an activity in my app. When i click one option, start running my service foreground with a notification like this:
PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0,
new Intent(getApplicationContext(), Radio.class),
PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification();
notification.tickerText = "Connecting RadiO!.. Wait..";
notification.icon = R.drawable.ic_launcher;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.setLatestEventInfo(getApplicationContext(), "radiO!",
"Playing: " + songName, pi);
startForeground(1, notification);
Then, still running my activity, I click on my notification and I opened it without closing the previous activity. I must not have the same activity twice.
Upvotes: 1
Views: 2681
Reputation: 13705
What you are doing is creating a new instance of the activity you are trying to execute each time you click on the notification, in order to avoid it and reuse an already existing activity(if any), just set the activity as singleTask in the AndroidManifest.xml as shown below:
<activity
android:name=".YourActivity"
android:launchMode="singleTask"/>
Hope this helps.
Regards!
Upvotes: 4