Back Button to close app
<p>I have a splash screen which leads into a main navigational screen which has animations in it to introduce the buttons. Want I want is to close the app when the back button is pressed. It currently reloads the activity (main) when the return button is called - why is this?</p>

<p>I looked about on the forums and one way was to use the finish() method. I tried implementing this in the main.java class like this:</p>

<pre><code>public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if( keyCode == KeyEvent.KEYCODE_BACK ) 
    {     
        this.finish();

        return true;
    }
    return false;
}
</code></pre>

<p>But the above didn't do it - what am I doing wrong?</p>

<p>Cheers</p>

<p>UPDATE</p>

<p>Cheers all for swift reply but none of these works. But I think I may know why - my class only implements the onCreate() method and none others. Could this be why all the other methods are failing?</p>

<p>UPDATE</p>

<p>Hi - I sorted it but I don't, at this moment, understand why this works &amp; the other methods don't work:</p>

<pre><code>@Override
public boolean onKeyDown(int keyCode, KeyEvent event)  {
    if ( keyCode == KeyEvent.KEYCODE_BACK &amp;&amp; event.getRepeatCount() == 0 ) 
    {
        // do something on back.
        moveTaskToBack( true );
        return true;
    }

    return super.onKeyDown(keyCode, event);
}
</code></pre>

<p>So why would this work and the finish() method used in the onBackPressed() demonstrated by ekawas doesn't??</p>
