How to get any identifier of the topmost activity?
<p>I have a service and its behavior must change when topmost Activity changes. Say, Activity A is active and then service starts some kind of processing. This processing must stop when Activity A is no longer visible: user pressed "Back", "Home" or did anything else that makes Activity A invisible. This Activity A must not be aware of the service -- i.e. it must not have to explicitly inform the Service that it is going away.</p>

<p>In the nutshell, is there a way to:</p>

<ul>
<li>Get any kind of identification (object reference, class name, ID, etc.) of the topmost Activity,</li>
<li>Receive notification when topmost Activity changes?</li>
</ul>

<p>P.S. This may sound like malware behavior, but it is not! It is legitimate use-case!</p>

<p>Edit: Activities are not in my application. They can be just about anything -- browser, maps app, settings, etc.</p>
