Hmmmm ... unfortunately, I suspect there is no simple answer. I think that why the built-in media player and Pandora use notification to easily allow the user to return to the application to make him shut up.
If the activity flow is fairly linear, then the return from the application is the same as the return to the original activity.
The trick I used in one scenario was to have each action notify the service in onPause() and onResume() . The service will monitor them, and if for some period of time it received onPause() without subsequent onResume() , it was assumed that the user had left (HOME, incoming phone call, incoming text message, answering any application through a notification, etc. d.).
You can also watch ACTION_SCREEN_OFF broadcast Intents to process this script.
I'm sorry that I do not have a better answer for a silver bullet - maybe someone else will have a better idea.
source share