我是android开发的新手。我目前正在开发一个应用程序,将身份证上的图像与面部图像进行比较。从UploadActivity,用户将抓取身份证,点击“确定”后,系统将提示用户从LivenessActivity进入现场摄像,抓取用户的面部。假设在进行眨眼动作后,面部将被成功抓取并自动提示UploadActivity。在UploadActivity中,用户将点击按钮“viewface”,然后人脸图像会出现,但不幸的是,在采集人脸图像的过程中,LivenessActivity会不断出现,要求用户重新采集,但如果用户点击后退按钮,则会提示UploadActivity,如何避免LivenessActivity在采集人脸后继续出现?
这是我的Upload ActivityLivenessActivity供您参考:
上传活动:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_upload);

    txtPercentage = (TextView) findViewById(R.id.txtPercentage);

    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    imgPreview = (ImageView) findViewById(R.id.imgPreview);
    imgFace = (ImageView) findViewById(R.id.imgFace);
    btnCapturePicture = (Button) findViewById(R.id.btnCapturePicture);



    btnCapturePicture.setOnClickListener(new View.OnClickListener() {



        @Override
        public void onClick(View v) {

            captureImage();
        }

    });



    Intent i = getIntent();

    // boolean flag to identify the media type, image or video
    final boolean isImage = i.getBooleanExtra("isImage",true);
    previewMedia(isImage);
    if (fileUri != null)



      //call LivenessActivity
        startActivity(new Intent(UploadActivity.this,
        LivenessActivity.class));


    btnviewface = (Button) findViewById(R.id.btnviewface);
    btnviewface.setOnClickListener(new View.OnClickListener() {



        @Override
        public void onClick(View view) {

            Bundle extras = getIntent().getExtras();
            byte[] face = extras.getByteArray("image_best");

            //save byte[] in the sd card, make a folder
            try {
                Config.IMAGE_FACE = "/storage/emulated/0/Pictures/Android
          File Upload/IMG_face.jpg";
                FileOutputStream stream = new FileOutputStream(
          Config.IMAGE_FACE);
                stream.write(face);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

            Bitmap bmp = BitmapFactory.decodeByteArray(face, 0,
          face.length);
            imgFace.setImageBitmap(bmp);
            previewMedia(isImage);
            new UploadFileToServer(Config.IMAGE_DOC,
        Config.IMAGE_FACE).execute();

        }

    } );

活动:
@Override
public Detector.DetectionType onDetectionSuccess(DetectionFrame validFrame) {

    FaceIDDataStruct dataStruct = mDetector.getFaceIDDataStruct();
    if (dataStruct != null) {
        face = dataStruct.images.get("image_best");

        Intent intent = new Intent(LivenessActivity.this, UploadActivity.class);
        //facefileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
        //intent.putExtra("filePath", facefileUri.getPath());
        intent.putExtra("image_best",face);
        setResult(PAGE_INTO_LIVENESS, intent);

        startActivity(intent);

    }

    if (face == null) {
        face = validFrame.getCroppedFaceImageData();
    }//do something with liveness face
return DetectionType.DONE;

}

最佳答案

删除LivenessActivity中的startActivity而不是此调用finish()LivenessActivity.this.finish()

@Override
public Detector.DetectionType onDetectionSuccess(DetectionFrame validFrame) {

    FaceIDDataStruct dataStruct = mDetector.getFaceIDDataStruct();
    if (dataStruct != null) {
        face = dataStruct.images.get("image_best");

        Intent intent = new Intent(LivenessActivity.this, UploadActivity.class);
        //facefileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
        //intent.putExtra("filePath", facefileUri.getPath());
        intent.putExtra("image_best",face);
        setResult(PAGE_INTO_LIVENESS, intent);

        startActivity(intent); // Remove this
        finish(); // LivenessActivity.this.finish()

    }

    if (face == null) {
        face = validFrame.getCroppedFaceImageData();
    }//do something with liveness face
return DetectionType.DONE;

}

09-30 18:36