PictureCallback之后的完成活动

时间:2011-12-14 08:38:06

标签: android

我有一个CameraPreviewActivity,与我在这里的http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html非常相似

我宣布Handler在5秒后捕获图像,以便活动屏幕完全加载/稳定。

Handler aHandler = new Handler();
aHandler.postDelayed(new Runnable() {
    public void run() {                                                     
        mPreview.mCamera.takePicture(null, null, myPictureCallback_jpeg);
        // finish();
    }
}, 5000);

调用myPictureCallback_jpeg后,如何结束此活动?

2 个答案:

答案 0 :(得分:0)

使用,您的活动背景并尝试完成,

ActivityName.finish();

<activityContext>.finish(); // Its for example.. 

答案 1 :(得分:0)

我设法实现了回调接口。

public class CameraPreview extends Activity implements ActionCallBack {
      ...
      ...
      ...
    public void afterActionPerformed() {
        // TODO Auto-generated method stub
        this.finish();
    }
      ...
}

interface ActionCallBack {
    public void afterActionPerformed(); 
}

public class ActivityCallBack {
    private ActionCallBack cb;

    public ActivityCallBack(CameraPreview cp) { 
        cb = cp;
    }
    public void callBackMethod()
    {       
        cb.afterActionPerformed();   
    } 
}

class Preview extends SurfaceView implements SurfaceHolder.Callback {
    ActivityCallBack acb;
        ...
        ...
    Preview(Context context) {
         super(context);
         //con = context;       
         acb = new ActivityCallBack((CameraPreview) context);
    }
    ...
    ...

    PictureCallback myPictureCallback_jpeg = new PictureCallback() {
        public void onPictureTaken(byte[] imageData, Camera c) {
            String fileName = storeByteImage(imageData,
                    Integer.parseInt(imageQuality));

            // End the activity
            //((Activity) con).finish();
            acb.callBackMethod();

        }
    };