我认为 Intent 的额外大小限制是 1MB,如docs上所报道的那样。无论如何,我失去了一天追逐这个可怕的东西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)
不好的是 startActivity 失败了,但是 ActivityManager 不断地重新启动它,产生无限的进程。这似乎在这篇博文中得到了证实,作者在其中指出了86389 个字符的“限制”。我的相关代码很简单:
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);
ArrayList 空缺非常小,大约 8 个 POJO ,它被加载到一个 Thread 中,然后通过 Intent 的 extra 传递给一个新的活动。如果我将它增加到大约 90k,应用程序会无限循环,需要重新启动,这真的很烦人。还有其他人经历过吗?