我認爲Intent的額外限制爲1MB,如docs所報告。無論如何,我失去的一天追着這個可怕的TransactionTooLargeException
:開始新的活動時發生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保持一遍遍重新啓動它,產卵無限的過程。這似乎在this博客文章中得到確認,其中作者指示「限制」爲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,即獲取一個線程加載,然後通過意向的額外傳遞給新的活動。如果我增加到約90k,應用程序無限循環需要重新啓動,這是一個真正的煩惱。 其他人都遇到過這個問題?
有一個'putParcelableArrayList()'方法。我沒有看過源碼,但可能比使用普通的'putSerializable()'更有效率。 – paul 2013-02-15 19:10:01