我有一个活动,点击按钮相机活动被启动。有时 onActivityResult 被调用,有时不被调用。即使在重新启动设备后,onActivityResult 也不会被调用,也不会重新启动当前活动。这种奇怪的行为有什么解决办法吗?
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
String imageUri = data.toURI();
Uri uri = Uri.parse(imageUri);
try {
mBitmap = Media.getBitmap(getContentResolver(), uri);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// if result is ok returns the bitmap
// mBitmap = (Bitmap) data.getExtras().get("data");
mImageView.setImageBitmap(mBitmap);
new Thread(postTheImage).start();
} else {
Toast.makeText(getApplicationContext(), "Error during capturing the image", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v.getId() == R.id.capture_image_button) {
// Open the camera to capture the image
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
}