Switching layout whit onBackPressed()
<p>I want to switch between layouts using the physical back button. I found this:</p>

<pre><code>@Override
public void onBackPressed() {
RelativeLayout layout2 = (RelativeLayout)findViewById(R.id.layout2);// check if layout2 is open
if(layout2.getVisibility() == View.VISIBLE){
    setContentView(R.layout.main);
    return;
}else{
    super.onBackPressed(); 
    }

}
</code></pre>

<p>Is the checking part correct? </p>