Android ACTION_IMAGE_CAPTURE 有时不调用 onActivityResult

Android ACTION_IMAGE_CAPTURE sometimes not calling onActivityResult(Android ACTION_IMAGE_CAPTURE 有时不调用 onActivityResult)
本文介绍了Android ACTION_IMAGE_CAPTURE 有时不调用 onActivityResult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在我们的代码中,我们使用如下所示的 getPhoto 方法:

In our code we are using getPhoto method that looks like this:

public void getPhoto(View view) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    captureFile = new File(getCaptureFilePath());
    captureUri = Uri.fromFile(captureFile);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, captureUri);

    startActivityForResult(intent, CAPTURE_IMAGE);
}

和onActivityResult:

And onActivityResult:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    Log.w(TAG, "Came");

    if (resultCode == RESULT_OK) {
        if (requestCode == CAPTURE_IMAGE) {
            try {
                captureFile = new File(getCaptureFilePath());
                captureUri = Uri.fromFile(captureFile);

                Bitmap scaledBitmap = decodeFileAndResize(captureFile);
                saveResizedAndCompressedBitmap(scaledBitmap);

                Bitmap rotatedBitmap = convertToRotatedBitmap(scaledBitmap);
                driverPhoto.setImageBitmap(rotatedBitmap);

                Log.w(TAG, "Before recycle");

                if (rotatedBitmap != scaledBitmap) {
                    scaledBitmap.recycle();
                    scaledBitmap = null;
                    System.gc();
                }

                Log.w(TAG, "After recycle");
            } catch (IOException e) {
                BugSenseHandler.log(TAG, e);
            }
        }
    }
}

有时,当我按下确定"时,不会调用 onActivityResult(Came 未写入).我的代码有什么问题?

Sometimes, when I'm pressing 'Ok', onActivityResult is not called (Came not wrote). What is wrong in my code?

12-04 12:43:36.040: INFO/WindowManager(145): WIN DEATH: Window{40839990 com.skalar/com.skalar.activities.RegisterActivity paused=false}onActivityResult 未调用时出现在代码中.

12-04 12:43:36.040: INFO/WindowManager(145): WIN DEATH: Window{40839990 com.skalar/com.skalar.activities.RegisterActivity paused=false} appears in code when onActivityResult not called.

推荐答案

您的活动是否可能被杀死,这就是 onActivityResult 没有被执行的原因?当相机 Intent 返回时,通常会执行 onActivityResult 后跟 onResume.在 onPause 和 onResume 方法中添加一条日志语句并检查执行顺序.

Is it possible that your activity is getting killed and that is the reason on onActivityResult is not getting executed? When the camera Intent returns, normally onActivityResult followed by onResume will be executed. Put a log statement in your onPause and onResume methods and check the sequence of execution.

这篇关于Android ACTION_IMAGE_CAPTURE 有时不调用 onActivityResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Show progress during FTP file upload in a java applet(在 Java 小程序中显示 FTP 文件上传期间的进度)
How to copy a file on the FTP server to a directory on the same server in Java?(java - 如何将FTP服务器上的文件复制到Java中同一服务器上的目录?)
FTP zip upload is corrupted sometimes(FTP zip 上传有时会损坏)
Enable logging in Apache Commons Net for FTP protocol(在 Apache Commons Net 中为 FTP 协议启用日志记录)
Checking file existence on FTP server(检查 FTP 服务器上的文件是否存在)
FtpClient storeFile always return False(FtpClient storeFile 总是返回 False)