gpt4 book ai didi

Android TransactionTooLargeException 不知道是什么原因造成的

转载 作者:行者123 更新时间:2023-11-30 05:10:19 41 4
gpt4 key购买 nike

我不知道在我的一个 Fragment Screens 上导致此异常的原因和位置。

我尝试用这个 TooLargeTool 调试它我有这样的输出:

2-19 18:20:24.317 25554 25554 D TooLargeTool: * android:support:fragments = 23.9 KB
12-19 18:20:24.317 25554 25554 D TooLargeTool: * android:view_state = 0.1 KB
12-19 18:20:24.317 25554 25554 D TooLargeTool: * android-support-nav:fragment:defaultHost = 0.1 KB
12-19 18:20:28.735 25554 25554 D TooLargeTool: MainActivity.onSaveInstanceState wrote: Bundle@264718100 contains 3 keys and measures 2,554.3 KB when serialized as a Parcel
12-19 18:20:28.735 25554 25554 D TooLargeTool: * android:fragments = 0.4 KB
12-19 18:20:28.735 25554 25554 D TooLargeTool: * android:viewHierarchyState = 4.0 KB
12-19 18:20:28.735 25554 25554 D TooLargeTool: * android:support:fragments = 2,549.9 KB
12-19 18:20:28.736 25554 25554 D TooLargeTool: BillingFragment.onSaveInstanceState wrote: Bundle@217680829 contains 0 keys and measures 0.0 KB when serialized as a Parcel
12-19 18:20:28.759 25554 25554 D TooLargeTool: NavHostFragment.onSaveInstanceState wrote: Bundle@148914 contains 4 keys and measures 25.1 KB when serialized as a Parcel
12-19 18:20:28.759 25554 25554 D TooLargeTool: * android-support-nav:fragment:navControllerState = 0.9 KB
12-19 18:20:28.759 25554 25554 D TooLargeTool: * android:support:fragments = 23.9 KB
12-19 18:20:28.759 25554 25554 D TooLargeTool: * android:view_state = 0.1 KB
12-19 18:20:28.759 25554 25554 D TooLargeTool: * android-support-nav:fragment:defaultHost = 0.1 KB
12-19 18:20:37.247 25554 25554 D TooLargeTool: MainActivity.onSaveInstanceState wrote: Bundle@143078438 contains 6 keys and measures 1,432.2 KB when serialized as a Parcel
12-19 18:20:37.247 25554 25554 D TooLargeTool: * android:fragments = 0.4 KB
12-19 18:20:37.247 25554 25554 D TooLargeTool: * android:support:request_fragment_who = 0.1 KB
12-19 18:20:37.247 25554 25554 D TooLargeTool: * android:support:fragments = 1,427.5 KB
12-19 18:20:37.247 25554 25554 D TooLargeTool: * android:viewHierarchyState = 4.0 KB
12-19 18:20:37.247 25554 25554 D TooLargeTool: * android:support:request_indicies = 0.1 KB
12-19 18:20:37.247 25554 25554 D TooLargeTool: * android:support:next_request_index = 0.1 KB
12-19 18:20:37.248 25554 25554 D TooLargeTool: BillingFragment.onSaveInstanceState wrote: Bundle@249100391 contains 0 keys and measures 0.0 KB when serialized as a Parcel
12-19 18:20:37.282 25554 25554 D TooLargeTool: NavHostFragment.onSaveInstanceState wrote: Bundle@79386132 contains 4 keys and measures 25.1 KB when serialized as a Parcel
12-19 18:20:37.282 25554 25554 D TooLargeTool: * android-support-nav:fragment:navControllerState = 0.9 KB
12-19 18:20:37.282 25554 25554 D TooLargeTool: * android:support:fragments = 23.9 KB
12-19 18:20:37.282 25554 25554 D TooLargeTool: * android:view_state = 0.1 KB
12-19 18:20:37.282 25554 25554 D TooLargeTool: * android-support-nav:fragment:defaultHost = 0.1 KB

屏幕与其他屏幕没有太大区别,也没有这种异常(exception)。

我经常有这样的错误

 java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 1432340 bytes
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3781)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: android.os.TransactionTooLargeException: data parcel size 1432340 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:615)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3636)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3773)

我有自定义 View ,其中包含 ImageView,我认为这种情况可能会像这样将此图像保存在 Parcel 中:

internal class SavedState : ValidableTextInput.SavedState {

var iconState : Drawable? = null

constructor(superState: Parcelable) : super(superState) {}
private constructor(parcel: Parcel) : super(parcel) {
// order of reading must match order of writing
val bitmap = parcel.readParcelable(javaClass.classLoader) as Bitmap
this.iconState = BitmapDrawable(Resources.getSystem(), bitmap)
}

override fun writeToParcel(out: Parcel, flags: Int) {
super.writeToParcel(out, flags)

val bitmap = iconState?.toBitmap()
out.writeParcelable(bitmap, flags)
}

companion object CREATOR : Parcelable.Creator<ValidableIconTextInput.SavedState> {
override fun createFromParcel(parcel: Parcel): ValidableIconTextInput.SavedState {
return ValidableIconTextInput.SavedState(parcel)
}

override fun newArray(size: Int): Array<ValidableIconTextInput.SavedState?> {
return arrayOfNulls(size)
}
}
}

最佳答案

我发现我有 SavedState 的父类(super class),然后我还将可绘制的背景保存到包裹中。这最终导致了问题。

喜欢这里:

internal open class SavedState : View.BaseSavedState {

var textInputState: String? = null
var backgroundState: Drawable? = null

constructor(superState: Parcelable) : super(superState) {}
protected constructor(parcel: Parcel) : super(parcel) {
// order of reading must match order of writing
this.textInputState = parcel.readString()
val bitmap = parcel.readParcelable(javaClass.classLoader) as Bitmap
this.backgroundState = BitmapDrawable(Resources.getSystem(), bitmap)
}

override fun writeToParcel(out: Parcel, flags: Int) {
super.writeToParcel(out, flags)
// order of writing must match order of reading
out.writeString(this.textInputState)
val bitmap = backgroundState?.toBitmap()
out.writeParcelable(bitmap, flags)
}

override fun describeContents(): Int {
return 0
}

companion object CREATOR : Parcelable.Creator<SavedState> {
override fun createFromParcel(parcel: Parcel): SavedState {
return SavedState(parcel)
}

override fun newArray(size: Int): Array<SavedState?> {
return arrayOfNulls(size)
}
}
}

关于Android TransactionTooLargeException 不知道是什么原因造成的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53856404/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com