Check whether activity is active
<p>I'm having a problem witch a listener in a certain activity. </p>

<p>The problem is that this listener contains an alert.show(); which can be called after we try to push a new activity (which then gives an exception).</p>

<p>e.g.: I'm listening in activity A for a signal from an other phone. I press back and try to run a new activity B but the program crashes because of the alert.show() A's listener.</p>

<pre><code>ERROR/AndroidRuntime(3573): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@476c21c0 is not valid; is your activity running?
</code></pre>

<p>Can I check in A's listener whether this activity is active and then show the alert or not depending on this value?</p>
