2

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 Being 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

3 Answers 3

8

Call setCancelable() on your Dialog or your AlertDialog.Builder, depending on how you are creating this dialog.

2
  • 1
    If you don't want the cancel button to disable the dialog use false for setCancelable...
    – Janusz
    Nov 3, 2010 at 14:51
  • Exactly what I needed Jan 24, 2017 at 13:19
1

dialog.setcancellable(false);

it works perfect

-1

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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.