-
프로그램 종료 다이얼로그 띄우기JAVA/Android 2017. 10. 6. 00:31
BackPressCloseHandler.java
public class BackPressCloseHandler {
private Activity activity;
public BackPressCloseHandler(Activity activity) {
this.activity = activity;
}
public void onBackPressed() {
AlertDialog.Builder ad = new AlertDialog.Builder(activity);
ad.setTitle("시스템 종료");
ad.setMessage("프로그램을 종료 하시겠습니까?").setCancelable(false).setPositiveButton("확인", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// 'YES'
activity.finish();
}
}).setNegativeButton("취소", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// 'NO'
return;
}
});
ad.create();
ad.show();
}
}MainActivity.java
public class HomeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
}
@Override
public void onBackPressed() {
//super.onBackPressed();
new BackPressCloseHandler(this).onBackPressed();
}
}'JAVA > Android' 카테고리의 다른 글
안드로이드 로딩화면 만들기 (0) 2017.10.01