Changing the behavior of a button depending on whether an activity is launched
<p>I have a transparent activity that gets launched on top of another activity. For the purposes of clarity, lets say that the transparent activity is called CommentsView, which is launched from an activity called ArticleView. </p>

<p>At the bottom of the ArticleView activity is a button that launches the CommentsView activity on top of it. While the CommentsView activity is launched, I would like to change the functionality of that button so that, when clicked again, it cancels the CommentsView activity and returns to ArticleView. </p>

<p>How can I go about doing this. I've tried adding a new onclicklistener to that button within the CommentsView activity, but I get a <code>NullPointerException</code> (presumably because that button doesn't exist in that activity). I've also tried handling this within the ArticleView activity, by creating a boolean variable <code>commentsLaunched</code> and using an if statement to either launch CommentsView (if <code>commentsLaunched == false</code>) or cancel it (if <code>commentsLaunched == true</code>). However, when I try this method I get a compiler error: <code>The final local variable commentClicked cannot be assigned, since it is defined in an enclosing type</code>. I can't define the commentClicked variable within the listener, or it will get re-initialized each click and thus be worthless.</p>

<p>How can I go about achieving my goal?</p>
