3

Fragment Screen の 1 つで、何がどこでこの例外を引き起こしているのかわかりません。

この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

画面は他の画面と大差なく、例外もありません。

私は常にそのようなエラーを持っています

 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)

内部に 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)
            }
        }
    }
4

1 に答える 1