java - finish() 方法未完成活动
问题描述
拍照后我正试图回到主要活动。
然而,finish() 方法并没有把我带回主活动。这是我的代码。
protected void takePicture() {
ImageReader.OnImageAvailableListener readerListener = new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader reader) {
Image image = null;
try {
image = reader.acquireLatestImage();
ByteBuffer buffer = image.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.capacity()];
buffer.get(bytes);
picture = bytes;
save(bytes);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (image != null) {
image.close();
}
}
}
private void save(byte[] bytes) throws IOException {
OutputStream output = null;
try {
output = new FileOutputStream(file);
output.write(bytes);
} finally {
if (null != output) {
output.close();
}
}
}
};
} catch (CameraAccessException e) {
e.printStackTrace();
}
while(picture == null);
sendImage(picture);
finish();
}
private void sendImage(byte[] bytes) {
Intent i = new Intent();
i.putExtra("picture", bytes);
setResult(1, i);
}
如果我运行这段代码,结果图片不为空,但 Activity 没有完成。如果我用 while(picture == null); 注释掉该行 结果图片为空,但活动在方法结束时完成。我希望图片不为空,并且要完成活动。任何帮助将不胜感激;
解决方案
推荐阅读
- android - Android O:Service.stopForeground 等效项
- c# - 使用具有多个属性值的 xpath 获取 xml doc 子节点
- sql - 如何在 Spark SQL 查询中定义 WINDOWING 函数以避免重复代码
- regex - 当“主题”字段为空/为空时,不调用 Gerrit 触发器事件
- swift - 如何创建一个看起来像铅笔素描在 Swift 中的视图边框?
- javascript - 如何在 rd 谷歌地图插件中包含谷歌地图 API 密钥
- javascript - 如何在 React Material-ui 日期选择器中设置日期按钮的样式
- angularjs - 为什么 gulp-main-npm-files 看不到 angular-spinkit?
- c# - 如何使用 SQL 计数功能
- angular - 使用时无法提交值输入(更改)