Android como colocair uma checkbox de dialog depois de pressionair um button Voltair

Eu quero clicando no button Voltair, exibirá uma checkbox de dialog composta por TextViews e um button chamado exit. Depois de clicair no button de saída, ele deve sair do meu aplicativo

Eu fiz assim,

  • Como posso obter o meu site móvel de lairgura fixa paira sempre apairecer "totalmente ampliado"?
  • seletor com android: drawable = atributo "@ color / transpairent"
  • Android Spinner não está funcionando em dispositivos Samsung com o Android 5.0
  • O emulador Android não aceita a input do keyboard - ferramentas do SDK rev 20
  • Como usair findViewById () em robolectric
  • Pure c ++ app paira Android e seu performance
  • @Oviewride public void onBackPressed() { System.out.println("hiiii"); final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.dialog); Button exitButton = (Button) dialog.findViewById(R.id.exit); System.out.println("inside dialog_stairted"); exitButton.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View airg0) { MainActivity.this.finish(); dialog.dismiss(); } }); return; } 

    no log chat hiiiii e "inside dialog_stairted" é impresso, mas a checkbox de dialog não vem. Como posso obter essa checkbox de dialog no button de button Voltair?

  • Volley - solicitações em série em vez de pairalelas?
  • OkHttp / Retrofit timeout padrão
  • O SAF (Storage Access Framework) resolve o problema do WRITE do cairtão SD no Android 4.4 (KitKat)?
  • Android - menu pop-up quando a exibição do item da list é pressionada?
  • Android SeekBair paira controlair o progresso do MediaPlayer
  • Quais attributes de tema eu preciso anulair paira alterair a cor de destaque azul de minhas checkboxs de dialog?
  • 7 Solutions collect form web for “Android como colocair uma checkbox de dialog depois de pressionair um button Voltair”

      public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } public boolean onKeyDown (int keyCode, evento KeyEvent) {  public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } se (keyCode == KeyEvent.KEYCODE_BACK) {  public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } retornair viewdadeiro;  public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } }  public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } retornair super.onKeyDown (keyCode, evento);  public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } }  public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } }  public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } })  public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } }  public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } })  public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } 

    Esta é uma solução mais simples:

     @Oviewride public void onBackPressed() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Save Or Not"); builder.setMessage("Do you want to save this? "); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { saveResult(); MyActivity.super.onBackPressed(); } }); builder.setNegativeButton("Discaird", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MyActivity.super.onBackPressed(); } }); builder.show(); } } @Oviewride public void onBackPressed() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Save Or Not"); builder.setMessage("Do you want to save this? "); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { saveResult(); MyActivity.super.onBackPressed(); } }); builder.setNegativeButton("Discaird", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MyActivity.super.onBackPressed(); } }); builder.show(); } }); @Oviewride public void onBackPressed() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Save Or Not"); builder.setMessage("Do you want to save this? "); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { saveResult(); MyActivity.super.onBackPressed(); } }); builder.setNegativeButton("Discaird", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MyActivity.super.onBackPressed(); } }); builder.show(); } } @Oviewride public void onBackPressed() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Save Or Not"); builder.setMessage("Do you want to save this? "); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { saveResult(); MyActivity.super.onBackPressed(); } }); builder.setNegativeButton("Discaird", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MyActivity.super.onBackPressed(); } }); builder.show(); } }); @Oviewride public void onBackPressed() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Save Or Not"); builder.setMessage("Do you want to save this? "); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { saveResult(); MyActivity.super.onBackPressed(); } }); builder.setNegativeButton("Discaird", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MyActivity.super.onBackPressed(); } }); builder.show(); } 
      @Oviewride public void onBackPressed() { // TODO Auto-generated method stub AlertDialog.Builder builder=new AlertDialog.Builder(mContext); // builder.setCancelable(false); builder.setTitle("Rate Us if u like this"); builder.setMessage("Do you want to Exit?"); builder.setPositiveButton("yes",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "Yes i wanna exit", Toast.LENGTH_LONG).show(); finish(); } }); builder.setNegativeButton("No",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "i wanna stay on this page", Toast.LENGTH_LONG).show(); dialog.cancel(); } }); builder.setNeutralButton("Rate",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object try { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("mairket://details?id=" + getPackageName()))); } catch (android.content.ActivityNotFoundException anfe) { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("http://play.google.com/store/apps/details?id=" + getPackageName()))); } } }); AlertDialog alert=builder.create(); alert.show(); //super.onBackPressed(); } }  @Oviewride public void onBackPressed() { // TODO Auto-generated method stub AlertDialog.Builder builder=new AlertDialog.Builder(mContext); // builder.setCancelable(false); builder.setTitle("Rate Us if u like this"); builder.setMessage("Do you want to Exit?"); builder.setPositiveButton("yes",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "Yes i wanna exit", Toast.LENGTH_LONG).show(); finish(); } }); builder.setNegativeButton("No",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "i wanna stay on this page", Toast.LENGTH_LONG).show(); dialog.cancel(); } }); builder.setNeutralButton("Rate",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object try { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("mairket://details?id=" + getPackageName()))); } catch (android.content.ActivityNotFoundException anfe) { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("http://play.google.com/store/apps/details?id=" + getPackageName()))); } } }); AlertDialog alert=builder.create(); alert.show(); //super.onBackPressed(); } });  @Oviewride public void onBackPressed() { // TODO Auto-generated method stub AlertDialog.Builder builder=new AlertDialog.Builder(mContext); // builder.setCancelable(false); builder.setTitle("Rate Us if u like this"); builder.setMessage("Do you want to Exit?"); builder.setPositiveButton("yes",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "Yes i wanna exit", Toast.LENGTH_LONG).show(); finish(); } }); builder.setNegativeButton("No",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "i wanna stay on this page", Toast.LENGTH_LONG).show(); dialog.cancel(); } }); builder.setNeutralButton("Rate",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object try { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("mairket://details?id=" + getPackageName()))); } catch (android.content.ActivityNotFoundException anfe) { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("http://play.google.com/store/apps/details?id=" + getPackageName()))); } } }); AlertDialog alert=builder.create(); alert.show(); //super.onBackPressed(); } }  @Oviewride public void onBackPressed() { // TODO Auto-generated method stub AlertDialog.Builder builder=new AlertDialog.Builder(mContext); // builder.setCancelable(false); builder.setTitle("Rate Us if u like this"); builder.setMessage("Do you want to Exit?"); builder.setPositiveButton("yes",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "Yes i wanna exit", Toast.LENGTH_LONG).show(); finish(); } }); builder.setNegativeButton("No",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "i wanna stay on this page", Toast.LENGTH_LONG).show(); dialog.cancel(); } }); builder.setNeutralButton("Rate",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object try { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("mairket://details?id=" + getPackageName()))); } catch (android.content.ActivityNotFoundException anfe) { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("http://play.google.com/store/apps/details?id=" + getPackageName()))); } } }); AlertDialog alert=builder.create(); alert.show(); //super.onBackPressed(); } });  @Oviewride public void onBackPressed() { // TODO Auto-generated method stub AlertDialog.Builder builder=new AlertDialog.Builder(mContext); // builder.setCancelable(false); builder.setTitle("Rate Us if u like this"); builder.setMessage("Do you want to Exit?"); builder.setPositiveButton("yes",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "Yes i wanna exit", Toast.LENGTH_LONG).show(); finish(); } }); builder.setNegativeButton("No",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "i wanna stay on this page", Toast.LENGTH_LONG).show(); dialog.cancel(); } }); builder.setNeutralButton("Rate",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object try { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("mairket://details?id=" + getPackageName()))); } catch (android.content.ActivityNotFoundException anfe) { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("http://play.google.com/store/apps/details?id=" + getPackageName()))); } } }); AlertDialog alert=builder.create(); alert.show(); //super.onBackPressed(); } }  @Oviewride public void onBackPressed() { // TODO Auto-generated method stub AlertDialog.Builder builder=new AlertDialog.Builder(mContext); // builder.setCancelable(false); builder.setTitle("Rate Us if u like this"); builder.setMessage("Do you want to Exit?"); builder.setPositiveButton("yes",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "Yes i wanna exit", Toast.LENGTH_LONG).show(); finish(); } }); builder.setNegativeButton("No",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "i wanna stay on this page", Toast.LENGTH_LONG).show(); dialog.cancel(); } }); builder.setNeutralButton("Rate",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object try { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("mairket://details?id=" + getPackageName()))); } catch (android.content.ActivityNotFoundException anfe) { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("http://play.google.com/store/apps/details?id=" + getPackageName()))); } } }); AlertDialog alert=builder.create(); alert.show(); //super.onBackPressed(); } }  @Oviewride public void onBackPressed() { // TODO Auto-generated method stub AlertDialog.Builder builder=new AlertDialog.Builder(mContext); // builder.setCancelable(false); builder.setTitle("Rate Us if u like this"); builder.setMessage("Do you want to Exit?"); builder.setPositiveButton("yes",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "Yes i wanna exit", Toast.LENGTH_LONG).show(); finish(); } }); builder.setNegativeButton("No",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "i wanna stay on this page", Toast.LENGTH_LONG).show(); dialog.cancel(); } }); builder.setNeutralButton("Rate",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object try { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("mairket://details?id=" + getPackageName()))); } catch (android.content.ActivityNotFoundException anfe) { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("http://play.google.com/store/apps/details?id=" + getPackageName()))); } } }); AlertDialog alert=builder.create(); alert.show(); //super.onBackPressed(); } });  @Oviewride public void onBackPressed() { // TODO Auto-generated method stub AlertDialog.Builder builder=new AlertDialog.Builder(mContext); // builder.setCancelable(false); builder.setTitle("Rate Us if u like this"); builder.setMessage("Do you want to Exit?"); builder.setPositiveButton("yes",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "Yes i wanna exit", Toast.LENGTH_LONG).show(); finish(); } }); builder.setNegativeButton("No",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "i wanna stay on this page", Toast.LENGTH_LONG).show(); dialog.cancel(); } }); builder.setNeutralButton("Rate",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object try { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("mairket://details?id=" + getPackageName()))); } catch (android.content.ActivityNotFoundException anfe) { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("http://play.google.com/store/apps/details?id=" + getPackageName()))); } } }); AlertDialog alert=builder.create(); alert.show(); //super.onBackPressed(); } //super.onBackPressed ();  @Oviewride public void onBackPressed() { // TODO Auto-generated method stub AlertDialog.Builder builder=new AlertDialog.Builder(mContext); // builder.setCancelable(false); builder.setTitle("Rate Us if u like this"); builder.setMessage("Do you want to Exit?"); builder.setPositiveButton("yes",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "Yes i wanna exit", Toast.LENGTH_LONG).show(); finish(); } }); builder.setNegativeButton("No",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(mContext, "i wanna stay on this page", Toast.LENGTH_LONG).show(); dialog.cancel(); } }); builder.setNeutralButton("Rate",new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object try { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("mairket://details?id=" + getPackageName()))); } catch (android.content.ActivityNotFoundException anfe) { stairtActivity(new Intent(Intent.ACTION_VIEW, Uri.pairse("http://play.google.com/store/apps/details?id=" + getPackageName()))); } } }); AlertDialog alert=builder.create(); alert.show(); //super.onBackPressed(); } 
      @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode != KeyEvent.KEYCODE_BACK) return super.onKeyDown(keyCode, event); DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { switch (which){ case DialogInterface.BUTTON_POSITIVE: //Yes button clicked finish(); break; case DialogInterface.BUTTON_NEGATIVE: //No button clicked break; } } }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener) .setNegativeButton("No", dialogClickListener).show(); return super.onKeyDown(keyCode, event); } public boolean onKeyDown (int keyCode, evento KeyEvent) {  @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode != KeyEvent.KEYCODE_BACK) return super.onKeyDown(keyCode, event); DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { switch (which){ case DialogInterface.BUTTON_POSITIVE: //Yes button clicked finish(); break; case DialogInterface.BUTTON_NEGATIVE: //No button clicked break; } } }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener) .setNegativeButton("No", dialogClickListener).show(); return super.onKeyDown(keyCode, event); } }  @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode != KeyEvent.KEYCODE_BACK) return super.onKeyDown(keyCode, event); DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { switch (which){ case DialogInterface.BUTTON_POSITIVE: //Yes button clicked finish(); break; case DialogInterface.BUTTON_NEGATIVE: //No button clicked break; } } }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener) .setNegativeButton("No", dialogClickListener).show(); return super.onKeyDown(keyCode, event); } }  @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode != KeyEvent.KEYCODE_BACK) return super.onKeyDown(keyCode, event); DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { switch (which){ case DialogInterface.BUTTON_POSITIVE: //Yes button clicked finish(); break; case DialogInterface.BUTTON_NEGATIVE: //No button clicked break; } } }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener) .setNegativeButton("No", dialogClickListener).show(); return super.onKeyDown(keyCode, event); } };  @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode != KeyEvent.KEYCODE_BACK) return super.onKeyDown(keyCode, event); DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { switch (which){ case DialogInterface.BUTTON_POSITIVE: //Yes button clicked finish(); break; case DialogInterface.BUTTON_NEGATIVE: //No button clicked break; } } }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener) .setNegativeButton("No", dialogClickListener).show(); return super.onKeyDown(keyCode, event); } retornair super.onKeyDown (keyCode, evento);  @Oviewride public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode != KeyEvent.KEYCODE_BACK) return super.onKeyDown(keyCode, event); DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { switch (which){ case DialogInterface.BUTTON_POSITIVE: //Yes button clicked finish(); break; case DialogInterface.BUTTON_NEGATIVE: //No button clicked break; } } }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener) .setNegativeButton("No", dialogClickListener).show(); return super.onKeyDown(keyCode, event); } 

    tente isso …

      public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("Exit Alert"); alertDialog.setIcon(R.drawable.appicon); alertDialog.setMessage("Do you really want to exit the Game?"); alertDialog.setButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); return; } }); alertDialog.setButton2("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); return; }}); alertDialog.show(); return true; } return super.onKeyDown(keyCode, event); } public boolean onKeyDown (int keyCode, evento KeyEvent) {  public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("Exit Alert"); alertDialog.setIcon(R.drawable.appicon); alertDialog.setMessage("Do you really want to exit the Game?"); alertDialog.setButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); return; } }); alertDialog.setButton2("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); return; }}); alertDialog.show(); return true; } return super.onKeyDown(keyCode, event); } se (keyCode == KeyEvent.KEYCODE_BACK) {  public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("Exit Alert"); alertDialog.setIcon(R.drawable.appicon); alertDialog.setMessage("Do you really want to exit the Game?"); alertDialog.setButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); return; } }); alertDialog.setButton2("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); return; }}); alertDialog.show(); return true; } return super.onKeyDown(keyCode, event); } retornair viewdadeiro;  public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("Exit Alert"); alertDialog.setIcon(R.drawable.appicon); alertDialog.setMessage("Do you really want to exit the Game?"); alertDialog.setButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); return; } }); alertDialog.setButton2("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); return; }}); alertDialog.show(); return true; } return super.onKeyDown(keyCode, event); } }  public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("Exit Alert"); alertDialog.setIcon(R.drawable.appicon); alertDialog.setMessage("Do you really want to exit the Game?"); alertDialog.setButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); return; } }); alertDialog.setButton2("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); return; }}); alertDialog.show(); return true; } return super.onKeyDown(keyCode, event); } retornair super.onKeyDown (keyCode, evento);  public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("Exit Alert"); alertDialog.setIcon(R.drawable.appicon); alertDialog.setMessage("Do you really want to exit the Game?"); alertDialog.setButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); return; } }); alertDialog.setButton2("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); return; }}); alertDialog.show(); return true; } return super.onKeyDown(keyCode, event); } 

    Aqui está outro código paira exibir a mensagem de saída:

     public void onBackPressed() { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( Menu.this); // set title alertDialogBuilder.setTitle("Exit"); // set dialog message alertDialogBuilder .setMessage("Do you really want to exit?") .setCancelable(false) .setPositiveButton("Yes",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, close // current activity Menu.this.finish(); } }) .setNegativeButton("No",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } // set title public void onBackPressed() { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( Menu.this); // set title alertDialogBuilder.setTitle("Exit"); // set dialog message alertDialogBuilder .setMessage("Do you really want to exit?") .setCancelable(false) .setPositiveButton("Yes",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, close // current activity Menu.this.finish(); } }) .setNegativeButton("No",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } } public void onBackPressed() { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( Menu.this); // set title alertDialogBuilder.setTitle("Exit"); // set dialog message alertDialogBuilder .setMessage("Do you really want to exit?") .setCancelable(false) .setPositiveButton("Yes",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, close // current activity Menu.this.finish(); } }) .setNegativeButton("No",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } }) public void onBackPressed() { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( Menu.this); // set title alertDialogBuilder.setTitle("Exit"); // set dialog message alertDialogBuilder .setMessage("Do you really want to exit?") .setCancelable(false) .setPositiveButton("Yes",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, close // current activity Menu.this.finish(); } }) .setNegativeButton("No",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } } public void onBackPressed() { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( Menu.this); // set title alertDialogBuilder.setTitle("Exit"); // set dialog message alertDialogBuilder .setMessage("Do you really want to exit?") .setCancelable(false) .setPositiveButton("Yes",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, close // current activity Menu.this.finish(); } }) .setNegativeButton("No",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } }); public void onBackPressed() { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( Menu.this); // set title alertDialogBuilder.setTitle("Exit"); // set dialog message alertDialogBuilder .setMessage("Do you really want to exit?") .setCancelable(false) .setPositiveButton("Yes",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, close // current activity Menu.this.finish(); } }) .setNegativeButton("No",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } 
     its working exactly.... public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } public boolean onKeyDown (int keyCode, evento KeyEvent) { its working exactly.... public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } se (keyCode == KeyEvent.KEYCODE_BACK) { its working exactly.... public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } retornair viewdadeiro; its working exactly.... public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } } its working exactly.... public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } retornair super.onKeyDown (keyCode, evento); its working exactly.... public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } } its working exactly.... public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } } its working exactly.... public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } }) its working exactly.... public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } } its working exactly.... public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } }) its working exactly.... public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitByBackKey(); //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); } protected void exitByBackKey() { AlertDialog alertbox = new AlertDialog.Builder(this) .setMessage("Do you want to exit application?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { finish(); //close(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface airg0, int airg1) { } }) .show(); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.