How to go back on my app
<p>I want to re-implement the back button for my application..</p>

<p>For example, when the user clicks on the back button of the cellphone the app will move to the last page, and if this page is the first, quit application</p>

<p>I've already tried a lot of solutions that I found on the internet, but none of them worked.</p>

<p>Solutions that i already tried:</p>

<pre><code>@Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
         if (keyCode == KeyEvent.KEYCODE_BACK) {
             moveTaskToBack(true);
             return true;
         }
         return super.onKeyDown(keyCode, event);
     }
</code></pre>

<hr>

<pre><code>@Override
    public void onBackPressed ()
    {
        moveTaskToBack(true);
                return;
    }
</code></pre>

<hr>

<p>the only way that i got sucess is this:</p>

<pre><code>public boolean dispatchKeyEvent(KeyEvent event) {   
  // Handling the back button
  if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {

    Intent i = new Intent(this,BtConn.class);
    this.startActivity(i);
    return true;
  } else {
    return super.dispatchKeyEvent(event);
  }
}
</code></pre>

<p>but it's too slow.</p>

<p>My application is for Android 2.1</p>

<p>------------- edit -------------</p>

<p>Success, but one slow solution</p>

<pre><code>@Override
public void onBackPressed() { 

  if ( contentView == R.layout.main){
      Log.d("AQUI", "entro");
      finish();
  }else{
      Log.d("AQUI", "nao entro");
      this.finish();
      Intent i = new Intent(this,BtConn.class);
      this.startActivity(i);
  }  
}
</code></pre>
