title: How to make the back function and set the last contentView
body: <p>I hawe many view's in my application and now the problem is how to go back from one view to another.</p>
  
  <p>What I could do it by set back Buttons in every view but i would like to use the android back hard button.</p>
  
  <p>I have tried something like this:</p>
  
  <pre><code>public boolean onKeyDown(int keyCode, KeyEvent event) 
  {       
    if(keyCode==KeyEvent.KEYCODE_BACK)
            {
        finish();
            }
  return false;
  }
  </code></pre>
  
  <p>But the problem is that this will close my application.
  Could you please guide me for a  proper solution, for example to memorize the last view was set and then to come back to this view or something like this.</p>
  
  <p>Here is the code with which I am changing the view (it's a method in my main activity):</p>
  
  <pre><code>public void CheckIfUserIsLogedIn ()
  {
      int userPresence = localDatabase.CheckUserPresence();
      if (userPresence == 0) 
      {
          setContentView(R.layout.main);
      }
      else
      {
          setContentView(R.layout.userlogedon);
      }
  }  
  </code></pre>
  
  <p>Thank you.</p>