I have tried below code to return bitmap from child activity to parent activity and I am getting null pointer exception,
ByteArrayOutputStream stream = new ByteArrayOutputStream();
overlayImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
Intent intent=new Intent();
intent.putExtra("overlay",byteArray);
setResult(RESULT_OK, intent);
finish();
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
editorBitmapArray.add(current_bmp);
byte[] byteArray = getIntent().getByteArrayExtra("overlay");
current_bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
Image.setImage(current_bmp);
}
How to return byte array from child activity to parent activity in android?
you should get bitmap by data not getIntent()
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
editorBitmapArray.add(current_bmp);
byte[] byteArray = data.getByteArrayExtra("overlay");
current_bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
Image.setImage(current_bmp);
}
Use data
instead of getIntent()
to get ByteArray
in onActivityResult
:
byte[] byteArray = data.getByteArrayExtra("overlay");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With