Q:

Not allowing user exit the app using Home Button

In my app i do not want the user be able to exit my app on pressing the Home press key. There's a specific reason for not allowing the user to do this. Can anyone suggest what can be the correct way to achieve this?
At present what i am doing is Overriding the onKeyDown()-Method. The Code for it is as follows:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME) 
    {
       Intent intent = new Intent(this, LockScreen.class);
       intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       startActivity(intent);
    }
    return true;
}

In the Manifest file i am making changes as below:
<activity android:name=".LockScreen"
  android:screenOrientation="portrait"
  android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    <intent-filter>             
    <category android:name="android.intent.category.HOME"/>
    </intent-filter>
</activity>

A:

I agree with inazaruk but if you still want to do that then you need to override:
@Override
public void onAttachedToWindow() {

  this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
  super.onAttachedToWindow();

}

A:

Android doesn't support this scenario for simple apps, so you can't do this. 
Read this article by CommonsWare: Please ignore the Home Button. It will explain why handling Home button the way you want is not really a good idea.

