What to do on TransactionTooLargeException

前端 未结 30 3330
盖世英雄少女心
盖世英雄少女心 2020-11-22 03:08

I got a TransactionTooLargeException. Not reproducible. In the docs it says

The Binder transaction failed because it was too large.

D

相关标签:
30条回答
  • 2020-11-22 03:23

    I too got this exception on a Samsung S3. I suspect 2 root causes,

    1. you have bitmaps that load and take up too much memory, use downsizing
    2. You have some drawables missing from the drawable-_dpi folders, android looks for them in drawable, and resizes them, making your setContentView suddenly jump and use a lot of memory.

    Use DDMS and look at your heap as you play your app, that will give you some indication on which setcontentview is creating the issue.

    I copied all the drawables across all folders to get rid of problem 2.

    Issue is resolved.

    0 讨论(0)
  • 2020-11-22 03:23

    Recently I also have encountered with an interesting case while working with Android's Contacts Provider.

    I needed to load photos of contacts from internal contacts database and according to the system architecture all of this data are delivered by queries to Contacts Provider.

    As it works as a separate application - all kinds of data transferring are performed by using Binder mechanism and so Binder buffer comes into play here.

    My main mistake was that I didn't close the Cursor with blob data gotten from Contacts Provider, so that the memory allocated for the provider increased and this inflated the Binder buffer until I got tons of !!!FAILED BINDER TRANSACTION!!! messages in my LogCat output.

    So the main idea is that when you work with external Content Providers and got Cursors from them, always close it when you finish to work with them.

    0 讨论(0)
  • 2020-11-22 03:24

    Add this to your Activity

    @Override
    protected void onSaveInstanceState(Bundle oldInstanceState) {
        super.onSaveInstanceState(oldInstanceState);
        oldInstanceState.clear();
    }
    

    It works for me hope also it will help you

    0 讨论(0)
  • 2020-11-22 03:26

    I encountered this issue, and I found that when there huge amount of data getting exchanged between a service and an application,(This involves transferring lots of thumbnails). Actually data size was around 500kb, and the IPC transaction buffer size is set to 1024KB. I am not sure why it exceeded the transaction buffer.

    This also can occur, when you pass lot of data through intent extras

    When you get this exception in your application, please analyze your code.

    1. Are you exchanging lot of data between your services and application?
    2. Using intents to share huge data, (for example, the user selects huge number of files from gallery share press share, the URIs of the selected files will be transferred using intents)
    3. receiving bitmap files from service
    4. waiting for android to respond back with huge data (for example, getInstalledApplications() when the user installed lot of applications)
    5. using applyBatch() with lot of operations pending

    How to handle when you get this exception

    If possible, split the big operation in to small chunks, for example, instead of calling applyBatch() with 1000 operations, call it with 100 each.

    Do not exchange huge data (>1MB) between services and application

    I dont know how to do this, but, Do not query android, which can return huge data :-)

    0 讨论(0)
  • 2020-11-22 03:28

    Make sure that you do not put into Intent object data of large size. In my case I was adding String 500k size and then starting another activity. It always failed with this exception. I avoided sharing data between activities by using static variables of activities - you don't have to send them to Intent and then pulling from it.

    What I had:

    String html = new String();//some string of 500K data.
    Intent intent = new Intent(MainActivity.this, PageWebView.class);
    //this is workaround - I just set static variable and then access it from another    activity.
    MainActivity.htmlBody = timelineDb.getHTMLBodyForTweet(tweet);
    //This line was present and it actually failed with the same exception you had.
    //intent.putExtra("com.gladimdim.offtie.webview", html);
    
    0 讨论(0)
  • 2020-11-22 03:29

    So for us it was we were trying to send too large of an object through our AIDL interface to a remote service. The transaction size cannot exceed 1MB. The request is broken down into separate chunks of 512KB and sent one at a time through the interface. A brutal solution I know but hey - its Android :(

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