title: Override home and back button is case a boolean is true
body: <p>I was wondering if I can override the action of the back and home button is some cases. Normally these buttons should just react like they always do, but in a case some setting is true I want to override the buttons and let them call my own methods.</p>
  
  <p>I´m using these two methods to override these buttons:</p>
  
  <pre><code>  @Override
    public void onBackPressed() {    
    // call my backbutton pressed method when boolean==true
      }
  
    @Override
    public void onAttachedToWindow()    {                                                                                       this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);    
     super.onAttachedToWindow(); 
     // call my homebutton pressed method when boolean==true
     }
  </code></pre>