In this project you learn. When we click on back button then message shows again click for exit.

Java File MainActivity.java: –

public void onBackPressed() {
    if (doubleClick) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
    this.doubleClick = true;
    Toast.makeText(this, "Press BACK button again to exit", Toast.LENGTH_SHORT).show();
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            doubleClick = false;
        }
    }, 2000);
}
private boolean doubleClick = false;