package com.gsm_developers.backbutton_gsm;

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void onBackPressed() {
        backButtonEvent();
        return;
    }

    public void backButtonEvent() {
        AlertDialog.Builder hoshdar = new AlertDialog.Builder(MainActivity.this);

        hoshdar.setTitle("هشدار");
        hoshdar.setMessage("آیا قصد خروج از برنامه را دارید؟");

        hoshdar.setPositiveButton("بله",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                });

        hoshdar.setNegativeButton("خیر",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
        hoshdar.show();
    }
}
