मेरे पास एक गतिविधि है जिसमें जब मैं बैक बटन दबाता हूं तो यह चेतावनी संवाद नहीं दिखाता है। समस्या क्या हो सकती है? यहाँ मेरी कोडगतिविधि ऑनबैकप्रेस चेतावनी संवाद नहीं दिखा रहा है
@Override
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_search);
// 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
startActivity(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();
}
कृपया जांच करें() .... –
चेक, अगर आप क्योंकि आप मुख्य थ्रेड पर चलते दुर्घटना नहीं करते हैं? – IamStalker
वास्तव में इसे बुलाया जाता है लेकिन तुरंत आपकी गतिविधि समाप्त हो जाती है क्योंकि आपने 'super.onBackPressed(); 'लिखा है। यदि आप इसे हटाते हैं तो आपकी गतिविधि वापस नहीं समाप्त होती है और आपका संवाद दिखाया जाता है। – user370305