拍照后,后退按钮不工作

时间:2015-09-15 17:21:10

标签: android android-camera

我正在尝试实施我找到的解决方案HERE 但在我点击捕获后,后退按钮没有完成活动。有没有办法打电话

finish();

在功能

中按下后退按钮时
private void capture() {
    mCamera.takePicture(null, null, null, new Camera.PictureCallback() {
        final float bearing = degree;

        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            latitude = mGpsLocationTracker.getLatitude();
            longitude = mGpsLocationTracker.getLongitude();

            Toast.makeText(getApplicationContext(), "Picture Taken",
                    Toast.LENGTH_SHORT).show();

            Toast.makeText(getApplicationContext(), "" +
                    latitude + ", " + longitude, Toast.LENGTH_SHORT).show();

            Toast.makeText(getApplicationContext(), "" + bearing, Toast.LENGTH_SHORT).show();

            Intent intent = new Intent();
            intent.putExtra("image_arr", data);
            setResult(RESULT_OK, intent);
            camera.stopPreview();
            if (camera != null) {
                camera.release();
                mCamera = null;
            }
            finish();
        }
    });
}

@Override
public void onBackPressed() {
    super.onBackPressed();  
    finish();
}

2 个答案:

答案 0 :(得分:1)

确定而不是操作finish();尝试对所需的activity进行操作:

@Override
public void onBackPressed() {
    super.onBackPressed();
    startActivity(new Intent(YourActivity, DesiredActivity));
    finish();
}

答案 1 :(得分:0)

尝试覆盖活动类中的onKey方法

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) 
{   if (event.getAction() == KeyEvent.ACTION_UP) 
    {   finish();
    }
    return false;
};