问题
I wanted to return the image from AddMoreClaims to AddClaims listView
. When I click the submit button
in AddMoreClaims , I get message E/JavaBinder﹕ !!! FAILED BINDER TRANSACTION !!!
.
I use this method but still getting this annoying message !
AddMoreClaims
Bitmap bmp,photo;
byte[] bytes;
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case RESULT_LOAD_IMAGE:
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK & data != null && data.getData () !=null) {
selectedImage = data.getData();
try
{
photo= MediaStore.Images.Media.getBitmap(getContentResolver(), selectedImage);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.PNG, 100, stream);
bytes= stream.toByteArray();
bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
imageView.setImageBitmap(bmp); // image get displayed
}catch(IOException e)
{
e.printStackTrace();
}
}
break;
The selected image will be displayed on imageView
AddMoreClaims.
When submit button
is clicked, I want it return to AddClaims.
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent returnIntent = new Intent();
returnIntent.putExtra("BMP", bmp);
setResult(Activity.RESULT_OK, returnIntent);
finish();
}
});
What's wrong here ? Have I missed out anything ?
回答1:
I think you are not compressing the bmp where you should do it.
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent returnIntent = new Intent();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] bytes = stream.toByteArray();
returnIntent.putExtra("BMP", bytes);
setResult(Activity.RESULT_OK, returnIntent);
finish();
}
});
Then you should to uncompress where you need to show the image
byte[] bytes = data.getByteArrayExtra("BMP");
Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
imageView.setImageBitmap(bmp);
回答2:
Don't use compress large data into intent, this will consume more cpu and time,
see this thread.
If compressed data also exceed the limit of binder, also get this error: !!! FAILED BINDER TRANSACTION !!!
来源:https://stackoverflow.com/questions/34540819/still-get-error-failed-binder-transaction-although-have-compressed-it