jagrakye jagrakye - 10 months ago 40
Android Question

Is there a way for a notification to know the application is already open? Or specifically which activity is open?

I've got an activity that only opens via a notification. That notification can pop up while in the activity as well. Is there a way to tell the notification the activity is already open so I can change its behavior accordingly?


There is no way for the notification to know, it just has a PendingIntent that is fired when it's clicked. But you can be smart about handling the intent.

For your case I think you should look at Activity launch modes. Specifically I think adding launchMode="singleTop" to your <activity> tag in AndroidManifest.xml does exactly what you want.