Fixed
Status Update
Comments
fl...@gmail.com <fl...@gmail.com> #2
Hi Ed, Thank you so much for these suggestions. I've been reviewing them and merging them in. Hopefully it should be live. I've included a thank you note too in the article.
fl...@gmail.com <fl...@gmail.com> #3
Great! Thanks a lot, I'll look for the live updates soon!
il...@google.com <il...@google.com>
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-master-dev
commit b651a62816e8005a0e1c7fbd3435c01820f4c015
Author: Ian Lake <ilake@google.com>
Date: Thu Nov 29 21:44:16 2018
Create a new Lifecycle for Fragments after destruction
After a Fragment is destroyed (i.e., due to a
configuration change or removal from the FragmentManager),
the existing Lifecycle should remain in the terminal
DESTROYED state.
However, Fragments can be reused basically as a completely
new instance. In the initState() method which resets the
Fragment's state, we should also reset the Lifecycle
and SavedStateRegistry to ensure that the 'new' instance
is entirely independent from the old instance.
This fixes issues where developers would reuse a Fragment
and lifecycle.currentState would be DESTROYED in onCreate(),
causing any LiveData.observe calls to be ignored.
Test: updated FragmentLifecycleTest
BUG: 118880674
Change-Id: I7653eade8bac1a1101f3bba96198aae6a32ee264
M fragment/src/androidTest/java/androidx/fragment/app/FragmentLifecycleTest.java
M fragment/src/main/java/androidx/fragment/app/Fragment.java
https://android-review.googlesource.com/837643
https://goto.google.com/android-sha1/b651a62816e8005a0e1c7fbd3435c01820f4c015
Branch: androidx-master-dev
commit b651a62816e8005a0e1c7fbd3435c01820f4c015
Author: Ian Lake <ilake@google.com>
Date: Thu Nov 29 21:44:16 2018
Create a new Lifecycle for Fragments after destruction
After a Fragment is destroyed (i.e., due to a
configuration change or removal from the FragmentManager),
the existing Lifecycle should remain in the terminal
DESTROYED state.
However, Fragments can be reused basically as a completely
new instance. In the initState() method which resets the
Fragment's state, we should also reset the Lifecycle
and SavedStateRegistry to ensure that the 'new' instance
is entirely independent from the old instance.
This fixes issues where developers would reuse a Fragment
and lifecycle.currentState would be DESTROYED in onCreate(),
causing any LiveData.observe calls to be ignored.
Test: updated FragmentLifecycleTest
BUG: 118880674
Change-Id: I7653eade8bac1a1101f3bba96198aae6a32ee264
M fragment/src/androidTest/java/androidx/fragment/app/FragmentLifecycleTest.java
M fragment/src/main/java/androidx/fragment/app/Fragment.java
il...@google.com <il...@google.com> #5
This is fixed internally and will be available in Fragments 1.1.0-alpha03
Description
this is the first time I file a bug, so I don't really know how to do that properly.
I noticed that if I create a fragment instance in an activity, add it to the container, remove it with the FragmentTransaction's remove method (which destroys the fragment instance) and then later use the same fragment variable in the activity to add it back to the container (which calls onCreate again), no LifecycleObserver can be added in the fragment's onCreate method, because the fragment is still in DESTROYED state.