In my app I have a notification in the task bar and when clicked it starts a new Activity view of my program. However when I try and use the stop button to stop my service from within this view, nothing happens. I am assuming when I press the notification button that it does not keep my ACTIVITY linked with the service.
When my app is first opened, the service is started by using the Intent below:
Intent svc = new Intent(this, StreamService.class);
startService(svc);
Then in the service:
//Intent passed when notification is selected.
Intent notificationIntent = new Intent(this, HomeActivity.class);
Any idea how to link back to my running service? Or perhaps bring the original activity/view back to the front when the notification is selected?
The Intent that you can attach to the notification should have a service intent, with a specific action. In your service’s onStart method, you can check it’s a close action, and then you can call stopSelf().