You can block the back button by overwriting dispatchKeyEvent()
in your Activity
class, and returning true if event.getKeyCode()
is equal to KeyEvent.KEYCODE_BACK
. But you cannot block the Home button from going to the home page.
I have heard of some trickery where you register your application as a receiver of the android.intent.category.HOME
intent. This would cause the Android OS to load your activity if the user presses the home button. If you can get this to work, you could then load the "actual" home screen if the user has entered the correct password. This approach is likely to behave differently on different devices and Android versions, however, and it probably would do nothing to stop the Hold-Home task list from appearing.
The bottom line is the Android OS has been designed to prevent just the thing you are trying to do: an application should not be able to take control over the phone and prevent other applications (especially the Phone) from running.