backPressed() not working on second activity

Maybe this helps you

    @Override
    public void onBackPressed() {
        Intent gBack = new Intent(getActivity(),MainActivity.class);
        startActivity(gBack);
    }