简体   繁体   中英

TransactionTooLargeException when starting new Activity

I thought the Intent's extra limit in size was 1MB, as reported on docs . Anyway, I lost one day chasing this terrible TransactionTooLargeException :

 E/JavaBinder(368): !!! FAILED BINDER TRANSACTION !!!
 Exception when starting activity android/com.android.internal.app.ChooserActivity
 android.os.TransactionTooLargeException
at android.os.BinderProxy.transact(Native Method)
at    android.app.ApplicationThreadProxy.scheduleLaunchActivity(ApplicationThreadNative.java:705)
at com.android.server.am.ActivityStack.realStartActivityLocked(ActivityStack.java:690)
at com.android.server.am.ActivityStack.startSpecificActivityLocked(ActivityStack.java:799)
at com.android.server.am.ActivityStack.resumeTopActivityLocked(ActivityStack.java:1743)
at com.android.server.am.ActivityStack.resumeTopActivityLocked(ActivityStack.java:1381)
at com.android.server.am.ActivityStack.completePauseLocked(ActivityStack.java:1129)
at com.android.server.am.ActivityStack.activityPaused(ActivityStack.java:1027)
at com.android.server.am.ActivityManagerService.activityPaused(ActivityManagerService.java:4288)
at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:381)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:1611)
at android.os.Binder.execTransact(Binder.java:367)
at dalvik.system.NativeStart.run(Native Method)

the bad thing is that startActivity fails, but ActivityManager keeps restarting it over and over, spawning infinite processes. This seems to be confirmed on this blog post, where the author indicates a 'limit' of 86389 characters . My relevant piece of code is quite simple:

                    Intent myIntent = new Intent(activity, VacancySwipeActivity.class);
                    //myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    Bundle ex = new Bundle();
                    ex.putSerializable(Constants.Extra.VACANCY, vacancies);
                    ex.putString("token", token);
                    ex.putString("cosa", cosa.getText().toString());

                    ex.putInt("dist", searchDistance.getProgress());
                    ex.putString("dove", dove.getText().toString());
                    if (ret.getSearchLocation() != null) {
                        ex.putParcelable("userLoc", ret.getSearchLocation());
                    }
                    ex.putInt("totRows", ret.getTotFound());

                    myIntent.putExtras(ex);
                    activity.startActivity(myIntent);

The ArrayList vacancies is very small, about 8 POJO , that gets loaded in a Thread and then passed to a new activity via Intent's extra. If I increase it to about 90k, the app loops indefinitely requiring a reboot, a real annoyance. Anyone else experienced this ?

我有同样的问题,通过制作一个singelton Hashtable来解决它,我保存了我的“长”字符串,我只给出了意图中的密钥。

The limit is supposed to be 1MB but it varies by device from little less than 512KB up to almost a full 1MB. Apart from that you have another problem here. You're putting an ArrayList as an extra which is fine since ArrayList implements Serializable. But if you think that android will serialize this list to byte[] and transfer that you're wrong. It will serialize every item on its own and transfer that. And that is much more inefficient than it sounds. You should wrap the ArrayList in a wrapper object implementing Serializable and that will make a huge difference. See this blog post (mine) for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM