Still get error FAILED BINDER TRANSACTION although have compressed it

半城伤御伤魂 提交于 2019-12-20 06:29:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!