Fixed
Status Update
Comments
ka...@gmail.com <ka...@gmail.com> #2
The crash can be reproduced and fixed using this sample project. There is a commented line in FirstFragment
which fixes the issue.
Also I've manually implemented Parcelable in the sample project, to demonstrate that @kotlinx.parcelize.Parcelize isn't the cause of the issue.
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-main
commit 4776f596c08056c5e7234f3829de7698ad46296d
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon May 10 12:51:05 2021
Fix fragment result with parcelables
When using the fragment result API, if you put a parcelable into the
result bundle, your process dies, and your result listener attempts to
access the parcelable, you will get a class not found exception if you
do not set the classloader.
We should set the class loader on your bundle before returning the
listener callback to ensure the Parcelable classes are accesible.
RelNote: "You can now retrieve your Parcelable from the fragment result
bundle after process death."
Test: FragmentResultTest
Bug: 187443158
Change-Id: I6593233191347d9595f81268951d6f8dbb627273
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentResultTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
https://android-review.googlesource.com/1701765
Branch: androidx-main
commit 4776f596c08056c5e7234f3829de7698ad46296d
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon May 10 12:51:05 2021
Fix fragment result with parcelables
When using the fragment result API, if you put a parcelable into the
result bundle, your process dies, and your result listener attempts to
access the parcelable, you will get a class not found exception if you
do not set the classloader.
We should set the class loader on your bundle before returning the
listener callback to ensure the Parcelable classes are accesible.
RelNote: "You can now retrieve your Parcelable from the fragment result
bundle after process death."
Test: FragmentResultTest
Bug: 187443158
Change-Id: I6593233191347d9595f81268951d6f8dbb627273
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentResultTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
jb...@google.com <jb...@google.com> #4
This has been fixed internally and will be available in the Fragment 1.3.4
release via Fragment 1.4.0-alpha01
.
Description
Component used: Fragment Version used: 1.3.3 Devices/Android versions reproduced on: Emulator Android 10
Currently there is a crash trying to get parcelable from result after process restoration.
Setup:
MainActivity
,FirstFragment
andSecondFragment
.FirstFragment
toSecondFragment
.FirstFragment
callsgetParentFragmentManager().setFragmentResultListener()
inonViewCreated()
and listens for result.getParentFragmentManager().setResult()
on submit button click. Submit button does only that and doesn't navigate back toFirstFragment
.Bundle
viaputParcelable()
. We send backExampleClass
which implementsParcelable
using@kotlinx.parcelize.Parcelize
.Steps to reproduce:
SecondFragment
.FirstFragment
receives result inFragmentResultListener#onFragmentResult
and callsresult.getParcelable()
.android.os.BadParcelableException
There two ways to avoid crash:
result.setClassLoader(context.classLoader)
beforeresult.getParcelable()
.Is this something that should be fixed on Fragment or platform side?
What is the preferred workaround for the app developers in the meantime?