Android的ACTION_IMAGE_CAPTURE有时不叫onActivityResult [英] Android ACTION_IMAGE_CAPTURE sometimes not calling onActivityResult
问题描述
在我们的code,我们使用的是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);
}
}
}
}
有时候,当我pressing'确定', onActivityResult
不叫(来到
不写)。什么是错误的,我code?
Sometimes, when I'm pressing 'Ok', onActivityResult
is not called (Came
not wrote). What is wrong in my code?
编辑: 12月12日至4号:43:36.040:信息/窗口管理器(145):WIN死亡:窗口{40839990 com.skalar / com.skalar.activities。 RegisterActivity暂停= FALSE}
出现在code时, 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的原因是什么?当摄像机意图的回报,通常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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!