Android java binder FAILED BINDER TRANSACTION?

后端 未结 2 1981
生来不讨喜
生来不讨喜 2020-12-06 09:50

I am trying to download an image from service and display it in activity but I keep getting

 java binder FAILED BINDER TRANSACTION

This is

相关标签:
2条回答
  • 2020-12-06 10:17

    It fails because you are trying to send an image as an intent extra and it is too large for it. You can't send image using IPC communication technics like intents or service/binder, there is a limit of 1mb/10mb depending on version of android.

    0 讨论(0)
  • 2020-12-06 10:22

    Creating the cache of the image solves my problem

    private LruCache<String, Bitmap> mMemoryCache;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    ...
    // Get max available VM memory, exceeding this amount will throw an
    // OutOfMemory exception. Stored in kilobytes as LruCache takes an
    // int in its constructor.
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    
    // Use 1/8th of the available memory for this memory cache.
    final int cacheSize = maxMemory / 8;
    
    mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override
        protected int sizeOf(String key, Bitmap bitmap) {
            // The cache size will be measured in kilobytes rather than
            // number of items.
            return bitmap.getByteCount() / 1024;
        }
    };
    ...
    }
    
    public void addBitmapToMemoryCache(String key, Bitmap bitmap) {
    if (getBitmapFromMemCache(key) == null) {
        mMemoryCache.put(key, bitmap);
    }
     }
    
    public Bitmap getBitmapFromMemCache(String key) {
    return mMemoryCache.get(key);
    }
    

    Reference : Caching Bitmaps

    0 讨论(0)
提交回复
热议问题