title: How do I disable the Home button & Back button?
body: <p>I want way to disable the Home Button &amp; Back Button when a checkbox is checked in my application. I am on version 4.2.2. Here is my code, it does not work, the application stops when the box gets checked:</p>
  
  <pre><code>public void HardButtonOnClick(View v)
  {
      boolean checked1 = ((CheckBox) v).isChecked();
      if(checked1)
      {   
          SQLiteDatabase db;                      
          db = openOrCreateDatabase("Saftey.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
          db.setVersion(1);
          db.setLocale(Locale.getDefault());
          db.setLockingEnabled(true);
          ContentValues values = new ContentValues();
          values.put("hardBtn", "YES");
          db.update("Setting", values, "id = ?", new String[] { "1" });
          Toast.makeText(this, "Hard Button Locked", Toast.LENGTH_LONG).show();
          //SharedPreferences pref = getSharedPreferences("pref",0);
          //SharedPreferences.Editor edit = pref.edit();
          //edit.putString("hard","yes");
          //edit.commit();
          /* String Lock="yes" ;
           Bundle bundle = new Bundle();
           bundle.putString("key", Lock);
           Intent a = new Intent(Change_setting.this, ChildMode.class);
           a.putExtras(bundle);
           startActivity(a);*/
          super.onAttachedToWindow();
          this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
          isLock = true;
      }
      else
      {
          SQLiteDatabase db;                      
          db = openOrCreateDatabase("Saftey.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
          db.setVersion(1);
          db.setLocale(Locale.getDefault());
          db.setLockingEnabled(true);
          ContentValues values = new ContentValues();
          values.put("hardBtn", "NO");
          db.update("Setting", values, "id = ?", new String[] { "1" });
          //SharedPreferences pref = getSharedPreferences("pref",0);
          //SharedPreferences.Editor edit = pref.edit();
          //edit.putString("hard","no");
          //edit.commit();
          Toast.makeText(this, "Hard Button Un-Locked", Toast.LENGTH_LONG).show();
          isLock = false;
      }
  }
  </code></pre>
  
  <p>How can I make this work? I do not want to hide the buttons, I only want them to not respond to clicks when the checkbox is checked.</p>