Putting a Bitmap as Extra in a result Intent closes App completely

时间:2017-10-12 09:44:38

标签: android android-intent

When I return to the main activity from another activity and put a bitmap extra in the return Intent, the app finishes completely and onActivityResult in the main Activity is not called at all.

SecondaryActivity.java

private void returnFromModule(int result) {
    Intent intent = new Intent();
    intent.putExtra(CameraModule.Keys.KEY_FILE_PATH, mFilepath);
    //if the next line is omitted the app goes back normally to the main activity
    intent.putExtra("data", mThumbnail);
    setResult(result, intent);
    finish();
}

Note that everything works fine when i dont put a bitmap extra. The bitmap also isn't very large.

public static Bitmap getThumbnail(String filepath) {
    ExifInterface exifInterface = getExifInterface(filepath);
    byte[] thumbnailData = exifInterface.getThumbnail();
    Bitmap thumbnail = BitmapFactory.decodeByteArray(thumbnailData, 0, thumbnailData.length);
    return thumbnail;
}

This is the thumbnail Bitmap that is put in the intent.

MainActivity.java

Here is the onActivityResult of my MainActivity but i don't think it matters much since it isn't called at all when a Bitmap is put in the return Intent.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
           ((TextView)findViewById(R.id.path)).setText(data.getExtras().getString(CameraModule.Keys.KEY_FILE_PATH));
    }
}

}

here is how i start the SecondaryActivity

startActivityForResult(new Intent(this, SecondaryActivity.class),1);

1 个答案:

答案 0 :(得分:0)

您可以通过活动传递的内容有一个大小限制。你不能这样做。