Check out example codes for "onbackpressed android". It will help you in understanding the concepts better.

Code Example 1

@Override
public void onBackPressed() {
    new AlertDialog.Builder(this)
        .setTitle("Really Exit?")
        .setMessage("Are you sure you want to exit?")
        .setNegativeButton(android.R.string.no, null)
        .setPositiveButton(android.R.string.yes, new OnClickListener() {

            public void onClick(DialogInterface arg0, int arg1) {
                WelcomeActivity.super.onBackPressed();
            }
        }).create().show();
}

Code Example 2

@Override
    public void onBackPressed() {
        super.onBackPressed();
    }

Learn ReactJs, React Native from akashmittal.com