Use onBackPressed to save a file
<p>I want to allow users to save a list of favourite items from a list, so I display the full list using a Listview with checkboxes, and the user will check or uncheck items in the list.</p>

<p>When the user presses the back button, I want to be able to save the checked items out to a separate file on the SD card.</p>

<p>I'm using the following method in my Activity:</p>

<pre><code>@Override
  public void onBackPressed() {
  // TODO Auto-generated method stub

  }
</code></pre>

<p>However, the list that I create within my OnCreate method is not available within the onBackPressed method - ie it's out of scope.</p>

<p>If I try and pass the list into the onBackPressed method as follows:</p>

<pre><code>@Override
  public void onBackPressed(ArrayList&lt;HashMap&lt;String, Object&gt;&gt; checked_list) {
  // TODO Auto-generated method stub

  }
</code></pre>

<p>Then I get the error:</p>

<p>"The method onBackPressed(ArrayList>) of type SetFavourites must override or implement a supertype method" and Eclipse prompts to remove the @Override.</p>

<p>But when I do this, then the onBackPressed method never gets called.</p>

<p>How can I pass variables into the onBackPressed method so that I can perform actions on data within my Activity before exiting?</p>

<p>Thanks</p>
