从片段调用startActivityForResult不起作用

时间:2016-08-18 15:55:36

标签: android android-fragments

我试图在片段中拨打电话startActivityForResult,以便从相机中捕捉照片。问题是调用片段的方法onActivityResult,使用接收位图更新ImageView但是立即删除片段,并将片段替换为前一片段。任何人都可以帮助我。提前谢谢。

private void addButtonListener() {
    // TODO Auto-generated method stub
    buttonAddFoto.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View button) {
            // TODO Auto-generated method stub
            mListener.setIdButton(button.getId());
            //mListener.takeImageFromCamera();
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent.resolveActivity(getContext().getPackageManager()) != null) {
                 startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
             }
        }

    });
}

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d("FRAGMENT DENTRO ON ACTIVITY RESULT1","");
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == Activity.RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");

        this.circleImageView.setImageBitmap(imageBitmap);
        Log.d("FRAGMENT DENTRO ON ACTIVITY RESULT2","");

     }

}

0 个答案:

没有答案