在我們的代碼,我們使用getPhoto方法,看起來像這樣:的Android ACTION_IMAGE_CAPTURE有時不叫onActivityResult
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:
@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
沒有寫)。我的代碼有什麼問題?
編輯:12-04 12:43:36.040: INFO/WindowManager(145): WIN DEATH: Window{40839990 com.skalar/com.skalar.activities.RegisterActivity paused=false}
onActivityResult
未調用時出現在代碼中。
請參閱http://stackoverflow.com/a/20433752/192373 –