Handling Back key while showing a dialog in android
in my application i prompt for password in onResume(), and Before this i have already created view in onCreate() so it is compulsory for user to enter password But if user press the Back key password dialog get disappered and user easily use the application
when dialog is Be开发者_开发问答ing shown,if get key event for Back key then i can easily handle this for that purpose i implemented onBackPressed()/onKeyDown() methods of Activity But none get event for this key when dialog is on screen after dialog disappered these methods get event for Back key can anyone tell me how can i handle this case
thanks in advance
Call setCancelable()
on your Dialog
or your AlertDialog.Builder
, depending on how you are creating this dialog.
dialog.setcancellable(false);
it works perfect
You can do something like this :
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK && progressDialog.isShowing())
{
// DO SOMETHING
}
// Call super code so we dont limit default interaction
super.onKeyDown(keyCode, event);
return true;
}
精彩评论