問題描述
在我們的代碼中,我們使用如下所示的 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!