Block Back Button In Android
I want to block hardware back button in android ,in order to prevent from going back to other activity.. Thanks in advance...
Solution 1:
Here is code that allows you to handle the back key in an activity correctly on all versions of the platform:
@OverridepublicbooleanonKeyDown(int keyCode, KeyEvent event) {
if ( Integer.valueOf(android.os.Build.VERSION.SDK) < 7//Instead use android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR
&& keyCode == KeyEvent.KEYCODE_BACK
&& event.getRepeatCount() == 0) {
// Take care of calling this method on earlier versions of// the platform where it doesn't exist.onBackPressed();
}
returnsuper.onKeyDown(keyCode, event);
}
@OverridepublicvoidonBackPressed() {
// This will be called either automatically for you on 2.0// or later, or by the code above on earlier versions of the// platform.return;
}
sources:http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html
Post a Comment for "Block Back Button In Android"