It depends on the Activity's declaration in the manifest, or the Intent flags that you include.
For example, if you use FLAG_ACTIVITY_SINGLE_TOP
(or the activity has launchMode
set to "singleTop"
) then onNewIntent()
will be called on the existing activity instead of creating a new one.
In your example, you should pass an extra in the intent to indicate that you want to execute the "stop" action, then check for it in onNewIntent()
.
This is well explained in the official documentation about launch modes: http://developer.android.com/guide/components/tasks-and-back-stack.html#TaskLaunchModes
EDIT: However, since the ultimate objective was playing audio in background, using a Service is a more appropriate option. Check http://developer.android.com/guide/topics/media/mediaplayer.html#mpandservices
To control the service from the notification (i.e. play, pause, stop) you need to supply PendingIntents
created from with startService()
.