Why do have to use Double back press to exit?

Suppose you doing some task in your application by mistake you pressed Back button and close the application, so there might be a mechanism through which user must get a alert message Please Cilck Back Again To Exit once he clicks on back button and if user again clicks on back button then the application must be closed.

Step 1.  Create Android Project as name BackPress, Create empty Activity call MainActivity

Step 2.  Open MainActivity.java, modify it by writing below code To Back Press Event in Andriod Application


package com.divy.backpress;

import android.os.Handler;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


    boolean BackPress = false;


    protected void onCreate(Bundle savedInstanceState) {





    public void onBackPressed() {

        if (BackPress) {




        this.BackPress = true;

        Toast.makeText(this, "Please Click Back Again To Exit", Toast.LENGTH_SHORT).show();

        new Handler().postDelayed(new Runnable() {


            public void run() {



        }, 2000);



OutPut :-