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>
I agree with
inazarukbut if you still want to do that then you need to override: