How can I abort connecting to another device with WiFi Direct in the progress dialog?

I am trying to connect to a sensor. The problem is that for some reason I can only connect to the sensor if I do it twice. So I need to be able to abort the connection when my progress dialog is showing which is done by calling getActivity().cancelDisconnect();. But I don't know how to make it so that happens when I press the back button. How can this be done?

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    mContentView = inflater.inflate(R.layout.device_detail, null);
    mContentView.findViewById(R.id.btn_connect).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            WifiP2pConfig config = new WifiP2pConfig();
            config.deviceAddress = device.deviceAddress;
            config.wps.setup = WpsInfo.PBC;
            if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
            progressDialog = ProgressDialog.show(getActivity(), "Press back to cancel",
                    "Connecting to :" + device.deviceAddress, true, true
 //                        new DialogInterface.OnCancelListener() {
 //
 //                            @Override
 //                            public void onCancel(DialogInterface dialog) {
 //                                ((DeviceActionListener) getActivity()).cancelDisconnect();
 //                            }
 //                        }
            );
            ((DeviceListFragment.DeviceActionListener) getActivity()).connect(config);

        }
    });

    mContentView.findViewById(R.id.btn_disconnect).setOnClickListener(
            new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    ((DeviceListFragment.DeviceActionListener) getActivity()).disconnect();
                }
            });


    mContentView.findViewById(R.id.btn_start_client).setOnClickListener(
            new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // Allow user to pick an image from Gallery or other
                    // registered apps

                }
            });

    return mContentView;
}