Question

    final Dialog dailog = new Dialog(getActivity());
    LayoutInflater inflater = LayoutInflater.from(getActivity());

    dailog.setOnKeyListener(new OnKeyListener() {

    @Override
    public boolean onKey(DialogInterface dialog,int keyCode, KeyEvent event) {

            if (keyCode == KeyEvent.KEYCODE_BACK) {
                      getActivity().finish();//Line-9
            } 
    }
    });

    View dlgView = inflater.inflate(R.layout.xyz, null);
    dailog.setContentView(dlgView);
    ((Button) dlgView.findViewById(R.id.button_camera)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
            startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
            dialog.dismiss();
        }
    });
    dialog.show();

When camera get started and back key is pressed,Line-9 get also executed in some devices(like samsung s3). Is there any solution to solve this problem?

Était-ce utile?

La solution

when you start camera set boolean isCamaraOn = true;

and when camera is on and you press back button

then

 if(!isCameraOn){//go in only if camera is off
       if (keyCode == KeyEvent.KEYCODE_BACK) {
                  getActivity().finish();//Line-9
        }
 }

here you can set isCamaraOn to false;

try this, hope works for you

Autres conseils

The behavior of your program is correct. Please tell us what you are trying to do(expected behavior). So that we can help you

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top