나는 다시 버튼을 누르면 경고 대화 상자가 표시되지 않는 활동이 있습니다. 무엇이 문제 일 수 있습니까? 다음은 super.onBackPressed()를 제거해야 내 코드활동 onBackPress의 경고 대화 상자가 표시되지 않습니다.
@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();를 작성 했으므로 Activity가 호출되지만 즉시 Activity가 완료됩니다. 이것을 제거하면 활동이 뒤로 끝나지 않습니다. 대화 상자가 표시됩니다. – user370305