Reputation: 179
I would like to have my service perform something when the user presses Home or Back. I'm not looking to override or block the normal behavior of these buttons, just get notified about them.
I need to get notify even when the activity that started the service is stopped.
Working with platform 17-19.
Is there any way? Can it be done by intent-filter or broadcast receivers??
Thanks
Upvotes: 0
Views: 93
Reputation: 265
If the service is on you can use a broadcast by hooking into onPause or on onStop methods in the activity. if the service is not on I think you have to start it, do something, then end.
Upvotes: 0
Reputation: 868
Only Activities (and Fragments) will get these callbacks (onPause, onStop etc.). If your Activity is running, it can notify the service, but once it's in the background there is no way to do this.
Upvotes: 2