0

I got the !!! FAILED BINDER TRANSACTION !!! error when putting a scaled Bitmap as Base64 String into a HashMap and sending the map as Intent to called Activity.

@Override
protected Void doInBackground(byte[]... params) {
    byte[] bytes = params[0];
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
    int imgHeight = options.outHeight;
    int imgWidth = options.outWidth;
    if (imgHeight > 1920) imgHeight = 1024;
    if (imgWidth > 1080) imgWidth = 768;
    options.inJustDecodeBounds = false;
    options.inSampleSize = 8;

    image = Bitmap.createScaledBitmap(BitmapFactory.decodeByteArray(bytes,0,bytes.length,options), imgWidth, imgHeight, false);
    Items.put("image", base64EncodeDecode.encodeToBase64(image));

And here is the onClick method that finish this Activity.

        saveButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent returnIntent = new Intent();

            returnIntent.putExtra("Map", Items);
            returnIntent.putExtra("returncode", SAVE_CODE);
            setResult(RESULT_OK, returnIntent);
            finish();
        }

Some Information:

Items = HashMap<String,String>

If I set the line Items.put("image", base64EncodeDecode.encodeToBase64(image)); in comments, everything works.

What could be the problem?

I hope someone can help me.

Kind Regards!

raymondis
  • 356
  • 1
  • 5
  • 16

2 Answers2

2

There's a 1 MB size limit on the bundle you can send in intents. You should probably implement some global caching mechanism for your app and send the images cache id in the bundle. This is mentioned in the docs

guy.gc
  • 3,359
  • 2
  • 24
  • 39
  • Can you give me some hint how I can do this? – raymondis Feb 10 '16 at 11:40
  • 1
    For starters, your could implement an LRU cache as suggested here http://developer.android.com/reference/android/util/LruCache.html Have a single instance of this memory cache and keep it in your Application object. If the image you are trying to pass was downloaded from the internet - you could use it's url as an id in the cache. then simply send the url in the bundle – guy.gc Feb 10 '16 at 11:42
  • Can I send the LruCache via Intent to other Activities? Where can I read something about bundle? I want to get more Informations about that so something like this won't happen again. Thank you! – raymondis Feb 10 '16 at 11:51
  • 1
    you dont need to send LruCache via intent just pass the image url in intent and use the same LurCache class to download the image it will return image from local cache files. – Silvans Solanki Feb 10 '16 at 12:08
2

I had come with the same issue a few weeks back. so i stored the bitmap in phone file system and passed the file path to the intent. On the other hand i just retrieved the file. You might have to use async task while writing to the bitmap to file system.

mdb
  • 166
  • 8