Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 539
Shine Avatar asked Feb 15 '13 15:02

Shine


People also ask

How do I stop TransactionTooLargeException?

The key to avoiding TransactionTooLargeException is to keep all transactions relatively small. Try to minimize the amount of memory needed to create a Parcel for the arguments and the return value of the remote procedure call. Avoid transferring huge arrays of strings or large bitmaps.

What is start activity?

Starting activities or services. To start an activity, use the method startActivity(intent) . This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent.


1 Answers

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.

like image 82
Nemanja Kovacevic Avatar answered Nov 15 '22 05:11

Nemanja Kovacevic