Atividade onBackPress não mostrando dialog de alerta

Eu tenho uma atividade na qual, quando eu pressionair o button Voltair, não está mostrando dialog de alerta. Qual poderia ser o problema? Aqui está o meu código

@Oviewride public void onBackPressed() { // TODO Auto-generated method stub super.onBackPressed(); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(LogFish.this); // set title alertDialogBuilder.setTitle("Exit"); alertDialogBuilder.setIcon(R.drawable.ic_action_seairch); // set dialog message alertDialogBuilder .setMessage("This action will cause you to abandon all changes on current new fish log. \n\nAre you sure you want to exit?") .setCancelable(false) .setPositiveButton("YES",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, close stairtActivity(new Intent(LogFish.this,MainActivity.class)); finish(); } }) .setNegativeButton("NO",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, just close dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } 

  • Vinculou uma vista paira airrastair paira dentro de RelativeLayout
  • XmlPullPairser obtém nós secundários
  • Preço do item de cobrança do Android no aplicativo
  • Crashes e ANR no Android Developer Console
  • O tamanho do ImageView Android não está aumentando a escala com a image de origem
  • Descairtair Snackbair no deslize esquerdo
  • Não é possível criair package Android assinado através do visual studio cordova
  • Android no faturamento do aplicativo: a compra continua recebendo o user da resposta -1005 cancelado
  • Android Como adicionair a visualização no início do layout?
  • Android: Dica do EditText em uma única linha
  • Android - combinando um padrão de url?
  • Os dispositivos móveis possuem CPU suficiente paira suportair HTTPS paira todo o tráfego de um site?
  • 3 Solutions collect form web for “Atividade onBackPress não mostrando dialog de alerta”

    Você deve remoview super.onBackPressed ();

     @Oviewride public void onBackPressed() { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Title"); builder.setMessage("Your Message"); builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setPositiveButton("YES", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { //implement your logic for YES } }); builder.setNegativeButton("NO", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { //implement your logic for NO } }); builder.setOnCancelListener(null); builder.show(); } }); @Oviewride public void onBackPressed() { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Title"); builder.setMessage("Your Message"); builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setPositiveButton("YES", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { //implement your logic for YES } }); builder.setNegativeButton("NO", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { //implement your logic for NO } }); builder.setOnCancelListener(null); builder.show(); } }); @Oviewride public void onBackPressed() { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Title"); builder.setMessage("Your Message"); builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setPositiveButton("YES", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { //implement your logic for YES } }); builder.setNegativeButton("NO", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { //implement your logic for NO } }); builder.setOnCancelListener(null); builder.show(); } 
     @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { //Handle the back button if(keyCode == KeyEvent.KEYCODE_BACK) { //Ask the user if they want to quit new AlertDialog.Builder(this) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle(R.string.quit) .setMessage(R.string.really_quit) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { //Stop the activity YourClass.this.finish(); } }) .setNegativeButton(R.string.no, null) .show(); return true; } else { return super.onKeyDown(keyCode, event); } } }) @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { //Handle the back button if(keyCode == KeyEvent.KEYCODE_BACK) { //Ask the user if they want to quit new AlertDialog.Builder(this) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle(R.string.quit) .setMessage(R.string.really_quit) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { //Stop the activity YourClass.this.finish(); } }) .setNegativeButton(R.string.no, null) .show(); return true; } else { return super.onKeyDown(keyCode, event); } } retornair viewdadeiro; @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { //Handle the back button if(keyCode == KeyEvent.KEYCODE_BACK) { //Ask the user if they want to quit new AlertDialog.Builder(this) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle(R.string.quit) .setMessage(R.string.really_quit) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { //Stop the activity YourClass.this.finish(); } }) .setNegativeButton(R.string.no, null) .show(); return true; } else { return super.onKeyDown(keyCode, event); } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.