---
title: "ZXing CaptureActivity黑屏问题"
author: "hemowolf"
date: "2013-02-06T11:05:31Z"
tags: ["ZXing", "surfaceView", "二维码", "黑屏"]
categories: ["移动开发"]
slug: "zxing-captureactivity"
draft: false
lastmod: "2013-02-06T11:05:31Z"
id: 1796766
url: "https://obacow.iteye.com/blog/1796766"
---

ZXing的CaptureActivity在其他activity切换回来时会出现黑屏现象，跟踪发现surfaceDestroyed并不一定能调用到。

   在ZXing项目找到zxing不支持tabhost的答复。

 

```
Project Member #1 srowen
The app doesn't use a TabHost. If you are writing your own app, indeed, you may need to write different code! this part is not a library that is supposed to work in other contexts.
```

 

   虽然项目采用tabactivity搭建框架，但CaptureActivity是单独的activity。

   针对surfaceDestroyed在activity切换时不会总是调用的问题，[https://github.com/commonsguy/cw-advandroid/tree/master/Camera/Preview/](https://github.com/commonsguy/cw-advandroid/tree/master/Camera/Preview/) 的解决方法值的参考。

也即是把打开摄像头的动作延迟到surfaceChanged时调用。