My app allows the user to press a button, it opens the camera, they can take a photo and it will show up in an imageview. If the user presses back or cancel while the camera
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == CAMERE_REQUEST && resultCode == RESULT_OK && data != null)
{
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
You can check if the resultCode equals RESULT_OK this will only be the case if a picture is taken and selected and everything worked. This if clause here should check every condition.
I faced this problem when I tried to pass a serializable model object. Inside that model, another model was a variable but that wasn't serializable. That's why I face this problem. Make sure all the model inside of an model is serializable.
I also encountered this question, I solved it through adding two conditions one is:
resultCode != null
the other is:
resultCode != RESULT_CANCELED
this is my case
startActivityForResult(intent, PICK_IMAGE_REQUEST);
I defined two request code PICK_IMAGE_REQUEST
and SCAN_BARCODE_REQUEST
with the same value, eg.
static final int BARCODE_SCAN_REQUEST = 1;
static final int PICK_IMAGE_REQUEST = 1;
this could also causes the problem
I had this error message show up for me because I was using the network on the main thread and new versions of Android have a "strict" policy to prevent that. To get around it just throw whatever network connection call into an AsyncTask.
Example:
AsyncTask<CognitoCachingCredentialsProvider, Integer, Void> task = new AsyncTask<CognitoCachingCredentialsProvider, Integer, Void>() {
@Override
protected Void doInBackground(CognitoCachingCredentialsProvider... params) {
AWSSessionCredentials creds = credentialsProvider.getCredentials();
String id = credentialsProvider.getCachedIdentityId();
credentialsProvider.refresh();
Log.d("wooohoo", String.format("id=%s, token=%s", id, creds.getSessionToken()));
return null;
}
};
task.execute(credentialsProvider);
My problem was in the called activity when it tries to return to the previous activity by "finishing." I was incorrectly setting the intent. The following code is Kotlin.
I was doing this:
intent.putExtra("foo", "bar")
finish()
When I should have been doing this:
val result = Intent()
result.putExtra("foo", "bar")
setResult(Activity.RESULT_OK, result)
finish()