发布的应用报了一堆这个错误,但是我一脸懵b,我压根没有传太多东西在binder里面啊。。
网上搜了N多,都是说不要传太多在binder里面啊诸如此类。。。
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
最后统计bug数据,发现报错的都是7.0,7.1或者8.0的机器,而且报错跟其他的分析不太一样,别的分析起码会说在什么时候确实传送了大数据,但是
我的报错是这样:
1 | 1 java.lang.RuntimeException:android.os.TransactionTooLargeException: data parcel size 533928 bytes |
关键词activityStopped其他的是没有这个关键词的
最后在stackoverflow搜到这样一篇:
报错一模一样
I updated Nexus 5X to Android N, and now when I install the app (debug or release) on it I am getting TransactionTooLargeException on every screen transition that has Bundle in extras. The app is working on all other devices. The old app that is on PlayStore and has mostly same code is working on Nexus 5X. Is anyone having the same issue?
1 | java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 592196 bytes |
然后靠谱的回答是:
At the end, my problem was with things that were being saved onSaveInstance, and not with things that were being sent to next activity. I removed all saves where I can’t control a size of objects (network responses), and now it’s working.
Update:
To preserve big chunks of data, Google is suggesting to do it with Fragment that retains instance. Idea is to create empty Fragment without a view with all necessary fields, that would otherwise be saved in Bundle. Add setRetainInstance(true); to Fragment’s onCreate method. And then save data in Fragment on Activity’s onDestroy and load them onCreate. Here is an example of Activity:
1 | public class MyActivity extends Activity { |
And example of Fragment:
1 | public class DataFragment extends Fragment { |
More about it, you can read here.
Done
最后应该是解决这个问题了,over,要细心发现区别,找到关键,不要听信不明白人的误导,也不要单纯相信报错,之前总结过很多次了。