Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 9th, 2012  |  syntax: None  |  size: 0.95 KB  |  hits: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. @Override
  2. public boolean onKeyDown(int keyCode, KeyEvent event) {
  3.   // Handle the back button
  4.   if (keyCode == KeyEvent.KEYCODE_BACK && isTaskRoot()) {
  5.     // Ask the user if they want to quit
  6.     new AlertDialog.Builder(this)
  7.         .setIcon(android.R.drawable.ic_dialog_alert)
  8.         .setTitle(R.string.quit)
  9.         .setMessage(R.string.really_quit)
  10.         .setPositiveButton(R.string.yes,
  11.             new DialogInterface.OnClickListener() {
  12.               public void onClick(DialogInterface dialog,
  13.                   int which) {
  14.                 // Stop the activity
  15.                 finish();
  16.               }
  17.             }).setNegativeButton(R.string.no, null).show();
  18.  
  19.     return true;
  20.   } else {
  21.     return super.onKeyDown(keyCode, event);
  22.   }
  23. }
  24.  
  25. procedure TSomeForm.CloseQuery(Sender: TObject; var ACtion: TCloseAction);
  26. begin
  27.   if MessageDlg(mtConfirmation, 'Really quit?', [mbYes, mbNo], 0) = mrNo then
  28.     Action := caNone;
  29. end;