0% found this document useful (0 votes)
19 views1 page

Even To Bot On Atras Android

This code handles the back button press in an Android application. When the back button is pressed, it displays an alert dialog box asking the user to confirm if they want to exit the app. If they click "OK", it finishes the current activity and exits the app. Any other key presses are forwarded to the default handler.

Uploaded by

dsdsds
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

Even To Bot On Atras Android

This code handles the back button press in an Android application. When the back button is pressed, it displays an alert dialog box asking the user to confirm if they want to exit the app. If they click "OK", it finishes the current activity and exits the app. Any other key presses are forwarded to the default handler.

Uploaded by

dsdsds
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

public boolean onKeyDown(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_BACK) {
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("Salir")
.setMessage("Ests seguro?")
.setNegativeButton(android.R.string.cancel, null)//sin listener
.setPositiveButton(android.R.string.ok, new
DialogInterface.OnClickListener() {//un listener que al pulsar, cierre la aplicacion
@Override
public void onClick(DialogInterface dialog, int which){
//Salir
ConsultActivity.this.finish();
}
})
.show();
// Si el listener devuelve true, significa que el evento esta procesado, y nadie
debe hacer nada mas
return true;
}
//para las demas cosas, se reenvia el evento al listener habitual
return super.onKeyDown(keyCode, event);
}

You might also like